How to fetch the cell value of excel sheet

Asked by Muthumanikandan on 2017-07-27

I am new to sikuli python script:

Now i am facing a problem in selecting a cell value from excel sheet and want to put the same value in my windows application.

I dont know how to fetch the cell value from excel to my application,Kindly give me a solution.

If possible please explain the code with simple example.

I already go through the faq2208 i am not clear with it, so give me some other solutions.

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Muthumanikandan
Solved:
2017-07-27
Last query:
2017-07-27
Last reply:
2017-07-27

This question was reopened

RaiMan (raimund-hocke) said : #1
Muthumanikandan (nmuthu1) said : #2

We are not clear with faq2208, so can you please explain with simple example.

i have few questions on that faq,
1)Is i need to convert xlsx to csv,if yes help me to convert

please provide fully coded explanation

Manfred Hampl (m-hampl) said : #3

See the last paragraph of faq 2208

*** looking for docs
 xlrd1 is based on the original xlrd - download from here
http://pypi.python.org/packages/source/x/xlrd/xlrd-0.7.1.zip

This one contains some useful docs and examples in the contained xlrd folder and you might use this one as well.

(Remark: the current version of xlrd is 1.0.0)

**Quick start**:

```
    import xlrd
    book = xlrd.open_workbook("myfile.xls")
    print "The number of worksheets is", book.nsheets
    print "Worksheet name(s):", book.sheet_names()
    sh = book.sheet_by_index(0)
    print sh.name, sh.nrows, sh.ncols
    print "Cell D30 is", sh.cell_value(rowx=29, colx=3)
    for rx in range(sh.nrows):
        print sh.row(rx)
    # Refer to docs for more details.
    # Feedback on API is welcomed.

```

RaiMan (raimund-hocke) said : #4

please consult the docs of the xlrd module as mentioned in the faq

xlrd allows, to directly access Excel sheets per cell and more.

converting the Excel sheet to csv is a fallback option and should always work.

The docs for every Python module have code examples and the net is full of it.

masuo (masuo-ohara) said : #5

If you are using Sikuli IDE, try following codes.

import xlrd
import datetime
EXCELFILE = "C:\\temp\\book1.xls"

book = xlrd.open_workbook(EXCELFILE)
sheet = book.sheet_by_index(0)
for col in range(sheet.ncols):
    for row in range(sheet.nrows):
        celltype = sheet.cell_type(row,col)
        value = sheet.cell_value(row,col)
        if celltype == 1:
            print "col:%d row:%d value:%s" % (col,row,value)
        elif celltype == 2:
            print "col:%d row:%d value:%d" % (col,row,value)
        elif celltype == 3:
            s = datetime.datetime(*xlrd.xldate_as_tuple(value,book.datemode)).strftime("%Y/%m/%d %H:%M:%S")
            print "col:%d row:%d value:%s" % (col,row,s)

Muthumanikandan (nmuthu1) said : #6

Thanks masuo, that solved my question.

Muthumanikandan (nmuthu1) said : #7

Thanks masuo,

The above code imported all my excel sheet values,but i want to fetch a single column (For ex: cell: H41) and i want to paste that values in m application text field

masuo (masuo-ohara) said : #8

When strings is in cell H41

row = 40
col = 7
value = sheet.cell_value(row,col)

click("textbox.png") #click your application text field
paste(value) #paste strings from CELL

Muthumanikandan (nmuthu1) said : #9

masuo thanks alot,

This solved my problem..