Passing data through excel sheet to sikuli(in MAC OS)

Asked by Swathi C

Hi, I am using Sikuli tool in MAC.
There is a scenario where I need to pass multiple user's first name and last name while registering in a site. Could you please tell me whether I can pass the multiple data through excel sheet. If so how?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Try the package xlrd, that is fully written in Python language and works like a charm together with Sikuli. It can read and write excel sheets.

http://pypi.python.org/pypi/xlrd

just download the zip version and unzip to a directory of your choice.

there is no need to run the install (this is only recommended, if you want to use it with Python directly).

in your script add:
dir_xlrd = "absolute path to the xlrd directory"
if not dir_xlrd in sys.path: sys.path.append(dir_xlrd)
import xlrd

now you can use it according to the xlrd docs.

Another possibility is to export the .xls to a .csv and use normal Python file operations (or the csv module).

Revision history for this message
Swathi C (swathi-chamuru) said :
#2

Thanks for the quick response.
I have one more query regaridng the same. I have copied the zip file xlrd-0.7.1.zip(md5) and placed on the desktop. Now where should I place the excel sheet? Do I need to place in the same path where the zip file is placed or in any location.
One more query is that zip files do not work in MAC, so will this file works in MAC.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

go back to comment #1 and read again carefully:

just download the zip version and UNZIP to a directory of your choice.

On Mac this is easily done by just double-clicking on the zip. The zip itself should be saved somewhere else as a backup.

About the usage of xlrd: consult the docs.

Revision history for this message
Santhosh Motamarry (santhosh-motamarry) said :
#4

hi raiman can u give a small example for this where exactly i have to use the above line of code in the script. and also what were the things to be done before running script like where to keep the excel sheet like that.

Revision history for this message
RaiMan (raimund-hocke) said :
#5

--- where exactly i have to use the above line of code
since this is an import, it has to be placed before the first usage of xlrd features

--- where to keep the excel sheet
put it wherever you like. the path has to be given to the sheet open function of xlrd

--- and again finally
About the usage of xlrd: consult the docs.

Revision history for this message
Swathi C (swathi-chamuru) said :
#6

Raiman,
Does the zip file contains any working example.I mean if I execute that example in the zip file n change the data in the excel sheet present in zip file will i get the result?
Do we need to add any step of code to import the excel sheet from the particular location like how we import excel data in QTP

Revision history for this message
RaiMan (raimund-hocke) said :
#7

see docs

Revision history for this message
Santhosh Motamarry (santhosh-motamarry) said :
#8

what docs and what are they give me the path

Revision history for this message
Swathi C (swathi-chamuru) said :
#9

Hi Raiman,
Good Morning....
I would like to know whether we need to add any extra step for importing the excel sheet apart from the step "import xlrd". Like in QTP we use 'DataTable.Import("D:\Insert Order1.xls")' statement.
If possible please give me some working example as a reference.It would help us a lot as we got struck up in the middle of the work.
Please give us the path where we can find the docs.

Revision history for this message
RaiMan (raimund-hocke) said :
#10

Too easy:
The package contains a read me and a doc folder in the xlrd folder.

Revision history for this message
Swathi C (swathi-chamuru) said :
#11

I would like to know whether we need to add any extra step for importing the excel sheet apart from the step "import xlrd". Like in QTP we use 'DataTable.Import("D:\Insert Order1.xls")' statement.
If possible please give me some working example as a reference.It would help us a lot as we got struck up in the middle of the work.
Please give us the path where we can find the docs.

Revision history for this message
RaiMan (raimund-hocke) said :
#12

If you do not change your behavior, then this will be the last time, I will look at your questions, seriously.

Just copying and pasting comments/questions without looking at the answers or doing significant work for yourself is really bad behavior.

Revision history for this message
Swathi C (swathi-chamuru) said :
#13

Hi,
The way you are answering is not correct. Please see the questionwhat I have posted. I asked you 2 main points

1.Like in QTP we use 'DataTable.Import("D:\Insert Order1.xls")' statement.

2.If possible please give me some working example as a reference.It would help us a lot as we got struck up in the middle of the work.

Without including the path of the excelsheet in the program how will the script recognise the excelsheet and take the data.

If you dont have the working example with you, you can tell that with respect. We hav read the docs and tried with the example present in the xlrd and it did not work correctly for us. That is the reason we are asking you again n again.

This blog is to give solutions to the people who are not familiar with sikuli and who want to know more about sikuli but not to give rude answers like change your behaviour or pointing at a person and saying that it is a bad behaviour.

Being a moderator this is not a way to answer to the questions rudely. Please see the question and the answer what you have given.

Revision history for this message
RaiMan (raimund-hocke) said :
#14

Sorry, you are misunderstanding something: I am not a moderator here.

I am just something like a Sikuli power user, that has decided to help other people her on a regular base.

And I am very, very patient with the people asking questions.

I spend some time on this "hobby" and I decide to whom I spend it and for what.

One of my expectations when trying to help, is that people do their home works and spend some effort in the case before coming back.

And if you look at the comment chain, one can see, that I could get the impression, that you did not do your homework.

And xlrd has nothing to do with Sikuli, it is basic Python usage. You already got much more, than you could expect here.

And I prefer to clearly say, why I will not look any longer at a thread instead of just stopping to react.

I admit, that I was a little bit setup, by your behavior in this thread and comment #12 might be not very diplomatic, but it is not really rude. Anyway, I apologize for using the wrong words, but not for the content.

Back to your "problem":

Including download it took 1 minute to find out, how to open a spreadsheet, by looking into the docs/xlrd.html:

open_workbook(filename=None, logfile=sys.stdout, verbosity=0, pickleable=True, use_mmap=USE_MMAP, file_contents=None, encoding_override=None, formatting_info=False, on_demand=False, ) [#]
Open a spreadsheet file for data extraction.

filename
The path to the spreadsheet file to be opened.

So in your case:
open_workbook("D:\Insert Order1.xls")

So pls. do not tell me that you have struggled a lot, to find out.

Revision history for this message
Santhosh Motamarry (santhosh-motamarry) said :
#15

hi raiman,

we are still facing some problem in giving inputs through excel sheet could you please let me know your free time so that i would send my code to you by which u can tell us where we are facing problem

Revision history for this message
Santhosh Motamarry (santhosh-motamarry) said :
#16

Main thing i am little bit confused regarding where to keep the following line of codes in my script.

dir_xlrd = "absolute path to the xlrd directory"
if not dir_xlrd in sys.path: sys.path.append(dir_xlrd)
import xlrd

open_workbook("D:\Insert Order1.xls")

Revision history for this message
RaiMan (raimund-hocke) said :
#17

*** recommended use of module xlrd on Windows

This eliminates the need, to manipulate sys.path

--- in program folder Sikuli X create a folder Lib
--- copy the xlrd folder contained in the downloaded zip to this folder .... \Sikuli X\Lib
--- in each Sikuli script, where you want to use xlrd, put an import xlrd at the beginning
--- use raw strings r"file-path" or double the backslashes in file name strings

For the usage of xlrd look into the docs, that are contained in the xlrd folder.

Revision history for this message
Alex Nilsson (benthien-nilsson) said :
#18

Just installed xlrd as described above, got the error:

NameError: name 'buffer' is not defined

It seems that the built-in function "buffer" is not present, but since it's seldom used anyway, a workaround is to edit \Sikuli-IDE\Lib\xlrd\timemachine.py and add this to line 14:
buffer = str
After which xlrd works like a charm.

Revision history for this message
Rateesh (rateeshrajesh) said :
#19

Hi All,

Just an info about my observation on importing the xlrd package:

I needed the xlrd package for Excel parsing in Sikuli. So I downloaded the latest xlrd package i.e ' xlrd 0.9.2' and put it in a 'C:\SikuliX\libs\' as suggested in above comments (Thanks Raimann!)

Then I tried to open an Excel sheet with the following commands:
import xlrd
book=xlrd.open_workbook(r'C:\Sikuli data\Excel\Test.xls')

But I got the following error:
[error] AttributeError ( 'module' object has no attribute 'open_workbook' )

--- (I'm not sure why I got this error since I have imported the xlrd package)

So as a workaround, I decided to integrate all the names in the xlrd package into my current namespace with the following command:
from xlrd import *

Now there is no need to address the names with module name and the following command solved the problem:
book=open_workbook(r'C:\Sikuli data\Excel\Test.xls')

Hope this is useful!!!

Regards,
Rateesh

Can you help with this problem?

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

To post a message you must log in.