import xlrd method not copying numbers

Asked by Muthumanikandan on 2017-07-28

i used following code to fetch the value from excel,

import xlrd
import datetime
EXCELFILE = "D:\\Muthu\\Datamanipulation\\book1.xlsx"
book = xlrd.open_workbook(EXCELFILE)
sheet = book.sheet_by_index(0)
celltype = sheet.cell_type(40,33)
value = sheet.cell_value(40,33)
openApp("notepad")
wait(2)
paste(value)

in the row40,col33 if the value is string(ex:10REC22M) script copy the value and paste.
But in the row40,col33 if the value is number(ex: 100388) i got the error

[error] TypeError ( paste(): 1st arg can't be coerced to String )

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2017-07-28
Last reply:
2017-07-28
Manfred Hampl (m-hampl) said : #1

You have to convert the numeric value into a string.
masuo has already given an example how to identify the type of the value from excel in another question.
If it is numeric, then you have to use the str() function first.

Muthumanikandan (nmuthu1) said : #2

The following code where i need to use str() function

import xlrd
import datetime
EXCELFILE = "D:\\Muthu\\Datamanipulation\\book1.xlsx"
book = xlrd.open_workbook(EXCELFILE)
sheet = book.sheet_by_index(0)
celltype = sheet.cell_type(40,33)
value = sheet.cell_value(40,33)
openApp("notepad")
wait(2)
paste(value)

i used str() after the value and before the value i got error

[error] TypeError ( paste(): 1st arg can't be coerced to String )

Manfred Hampl (m-hampl) said : #3

see https://answers.launchpad.net/sikuli/+question/653759

Try

...
celltype = sheet.cell_type(40,33)
value = sheet.cell_value(40,33)
if celltype == 2:
     value = str(value)
...
paste(value)

masuo (masuo-ohara) said : #4

[before]
paste(value)

[after]
if celltype == 2:
    value = str(value)

paste(value)

Can you help with this problem?

Provide an answer of your own, or ask Muthumanikandan for more information if necessary.

To post a message you must log in.