ExcelLibrary.Save Excel issue

2,221 views
Skip to first unread message

GAURAV DEORE

unread,
Jun 13, 2013, 8:06:24 PM6/13/13
to robotframe...@googlegroups.com
Hi All,

I have added ExcelLibrary in RFW. I trying to use "ExcelLibrary.Save Excel", its showing me error - Attribute Error : Nonetype object has no attribute .

If anyone have solution on this, please know me.

Thanks!

--
------------------------------
Warm Regards,
GAURAV S. DEORE.

Pekka Klärck

unread,
Jun 13, 2013, 8:15:03 PM6/13/13
to gaur...@gmail.com, robotframe...@googlegroups.com
2013/6/14 GAURAV DEORE <gaur...@gmail.com>:
>
> I have added ExcelLibrary in RFW. I trying to use "ExcelLibrary.Save Excel",
> its showing me error - Attribute Error : Nonetype object has no attribute .

Sounds like a bug in the library. Could you run tests using
`--loglevel debug` to get a traceback of the failure? It ought to show
where in the code the failure occurs.

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Gaurav Deore

unread,
Jun 14, 2013, 1:07:12 AM6/14/13
to robotframe...@googlegroups.com, gaur...@gmail.com

Hi PK,

 After run test with "--loglevel Debug" its gives error as below .

KEYWORD: ExcelLibrary.Save Excel ${FILELOCATION}
Documentation:

Saves the Excel file indicated by fname

Start / End / Elapsed: 20130614 10:29:17.650 / 20130614 10:29:17.650 / 00:00:00.000

10:29:17.650 DEBUG Got fname C:\RFW_Workspace\DT_TEST\Web Service Test Cases.xls

10:29:17.650 FAIL AttributeError: 'NoneType' object has no attribute 'save'

10:29:17.650 DEBUG Traceback (most recent call last): File "C:\Python27\lib\site-packages\ExcelLibrary.py", line 152, in save_excel self.tb.save(os.path.join(self.slash, self.tmpDir, fname))




So does it have any option to save EXCEL?

Thanks,
Gaurav

Pekka Klärck

unread,
Jun 14, 2013, 2:29:03 AM6/14/13
to gaur...@gmail.com, robotframe...@googlegroups.com
2013/6/14 Gaurav Deore <gaur...@gmail.com>
>
> After run test with "--loglevel Debug" its gives error as below .
>
> 10:29:17.650 FAIL AttributeError: 'NoneType' object has no attribute
> 'save'
> 10:29:17.650 DEBUG Traceback (most recent call last):
> File "C:\Python27\lib\site-packages\ExcelLibrary.py", line 152, in save_excel
> self.tb.save(os.path.join(self.slash, self.tmpDir, fname))

What happens is that attribute `tb` that the library has, and
apparently contains the Excel data, is None. Most likely the attribute
hasn't yet been initialized when you call Save. This could be causes
by a bug in the library or you using it somehow wrong. In the latter
case the error reporting definitely should be better, though.

> So does it have any option to save EXCEL?

I don't know this library at all and don't have time to look at it. I
recommend you first re-read library's documentation related to reading
and saving data. If it doesn't help, and nobody here can help you
either, you need to start looking at the code.

Kevin O.

unread,
Jun 14, 2013, 9:49:40 AM6/14/13
to robotframe...@googlegroups.com
I took a quick glance at the code. The tb attribute does not seem to get set unless you modify the workbook before saving or start off by creating a workbook.
This is a good example of when its a good idea to access your own attribute through a method (or make it a property instead of a raw attribute) rather than directly. I see this code duplicated all over the place, but not in save_excel:
if not self.tb:
                self.tb = copy(self.wb)
An example of this is how Selenium2Library uses self._current_browser()
This library has not made it past the proof of concept stage. It sure would be nice to have an Excel library.

Kevin 

Sathish Kumar

unread,
Mar 14, 2017, 6:04:54 PM3/14/17
to robotframework-users
I am new to this group and am using Robot Framework at my work. Thanks to all those people who made Robot Framework an amazing tool to work.

Just thought of contributing a small fix that I have made to write data into excel file and save it successfully.

I replaced code in put_string_to_cell function with:

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_TEXT:
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)

From original code, I have commented two lines (as indicated) and moved self.wb.sheets() under if not self.tb: condition

Things work greatly after this...

Open the library(C:\Python27\Lib\site-packages\ExcelLibrary) in pycharm or any other IDE  and modify/copy above code snippet.



Sathish

unread,
Mar 15, 2017, 11:41:18 AM3/15/17
to robotframework-users
Explored more, 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
 

moses daniel

unread,
Jan 12, 2018, 12:54:29 AM1/12/18
to robotframework-users
hi sathish,

I have replaced the code you have suggested and got some new errors as shown below.

FAILED ExcelLibrary Importing test library 'ExcelLibrary' failed: NameError: nam
e 'self' is not defined
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\robotide\lib\robot\utils\importer.py", lin
e 143, in _import
    return __import__(name, fromlist=fromlist)
  File "C:\Python27\lib\site-packages\ExcelLibrary\__init__.py", line 17, in <mo
dule>
    from ExcelLibrary import ExcelLibrary
  File "C:\Python27\lib\site-packages\ExcelLibrary\ExcelLibrary.py", line 376, i
n <module>
    if self.wb:

now the entire package is not working...so i reverted the change... 
in which version did you do this change?
Reply all
Reply to author
Forward
0 new messages