list index out of range- Excel Library

1,232 views
Skip to first unread message

DISHA MUNSHI

unread,
May 9, 2016, 10:14:27 AM5/9/16
to robotframework-devel
Hi 

This is my script code

Variable declared:

${Excel_File_Path}            C:\\Python27\\ExcelRobotTest\\

Keywords used:

Create Excel Workbook TestRun
Save Excel                 ${Excel_File_Path}Test.xls
Open Excel                 ${Excel_File_Path}Test.xls
log                                 Created & opened
Put String To Cell         TestRun                               0                   0                           yellow
Save Excel                 ${Excel_File_Path}Test.xls

But I am facing error as below.

FAIL : IndexError: list index out of range


I dont understand why??

Sathish Kumar

unread,
Mar 15, 2017, 3:12:58 PM3/15/17
to robotframework-devel
There is an issue with writing data to excel using excel library. use below to use excel library to write data:
Solution: Made a fix for excel library keywords 'Put String to Cell', 'Put Number to Cell' and 'Put Date to Cell'. Copy code snippet under each function to your excel library file.
Steps:
In pycharm, open the ExcelLibrary project - C:\Python27\Lib\site-packages\ExcelLibrary.
Open the ExcelLibrary.py file and copy code snippet under each function into your file
Then, execute command  python __init__.py, this will place compiled file into your ExcelLibrary package.

Only change is input date format, it should be given as dd-mm-yyyy

def put_string_to_cell(self, sheetname, column, row, value):
    
if self.wb:
my_sheet_index = self.sheetNames.index(sheetname)
if not self.tb:
self.wb.sheets()
self.tb = copy(self.wb)
if self.tb:
plain = easyxf('')
self.tb.get_sheet(my_sheet_index).write(int(row), int(column), value, plain)

Date input should be in format:  dd-mm-yyyy ex: 25-12-2016

def put_date_to_cell(self, sheetname, column, row, value):


if self.wb:
my_sheet_index = self.sheetNames.index(sheetname)
# cell = self.wb.get_sheet(my_sheet_index).cell(int(row), int(column))
# if cell.ctype is XL_CELL_DATE:
if not self.tb:
self.wb.sheets()
self.tb = copy(self.wb)
if self.tb:
print(value)
# dt = value.split('.')
# dti = [int(dt[2]), int(dt[1]), int(dt[0])]
# print(dt, dti)
ymd = datetime.strptime(value, '%d-%m-%Y')
print(ymd)
plain = easyxf('', num_format_str='d-M-yyyy')
self.tb.get_sheet(my_sheet_index).write(int(row), int(column), ymd, plain)

def put_number_to_cell(self, sheetname, column, row, value):

if self.wb:
my_sheet_index = self.sheetNames.index(sheetname)
# cell = self.wb.get_sheet(my_sheet_index).cell(int(row), int(column))
# if cell.ctype is XL_CELL_NUMBER:
if not self.tb:
self.wb.sheets()
self.tb = copy(self.wb)
if self.tb:
plain = easyxf('')
self.tb.get_sheet(my_sheet_index).write(int(row), int(column), float(value), plain)

Hope this will help lot of people who want to write data to excel.

Thanks
Sathish

Vishal Mundlye

unread,
Aug 15, 2017, 5:19:45 AM8/15/17
to robotframework-devel
Thanks Sathish, this fix works and resolves the index out of bound issue faced in ExcelLibrary.

Jahid Ullah

unread,
Aug 25, 2018, 2:55:49 AM8/25/18
to robotframework-devel
Hi, 
1) Will this solution work for RIDE?
2) I did not understand when you said: "Then, execute command  python __init__.py, this will place compiled file into your ExcelLibrary package.".  So I need to go to cmd and type what?

Adam

unread,
Sep 6, 2018, 2:44:32 AM9/6/18
to robotframework-devel
I dont think this works with RIDE.
Ive tried with no luck

Raghunath Jonnagadla

unread,
Mar 2, 2019, 5:49:06 PM3/2/19
to robotframework-devel
Hi Satish,

I have done the said changes.But I am getting "IOError: [Errno 22] invalid mode ('w+b') or filename:",Need your help on this.Tried many online suggestions but none worked.


Thanks,
Raghunath
Reply all
Reply to author
Forward
0 new messages