excel2img gives error "object has no attribute 'parent' "when used 2nd time

Viewed 1643

When using excel2img library to take snap of a specific section of a sheet , It is giving below error.

AttributeError: '<win32com.gen_py.Microsoft Excel 16.0 Object Library.Range instance at 0x2697515534376>' object has no attribute 'parent'

The same code worked when used for first time. But it stopped working after that. Just to specify, I am using the same office version as earlier, the only change that I did in between is I installed few Libraries. I dont know if it is due to that.

I tried to change the excel version to .xlsx from .xls. But then it is returning error

"OSError: Failed to open snap.xlsx".

Below is the code which I am using:

import excel2img

excel2img.export_img("snap.xls","alarm_BB1.png","Sheet1!A2:Q20")
excel2img.export_img("snap.xls","VSWR_BB1.png","","Sheet2!A2:Q50")
excel2img.export_img("snap.xls","alarm_BB2.png","","Sheet3!A2:Q20")
excel2img.export_img("snap.xls","VSWR_BB2.png","","Sheet4!A2:Q50")

Below is the error that I am getting:

 AttributeError: '<win32com.gen_py.Microsoft Excel 16.0 Object 
 Library.Range instance at 0x2697515188064>' object has no attribute 
 'parent'

Below is the snap excel file.both in xls and xlsx format.snap.xlsx

snap.xls

1 Answers

By using XLS file:

import excel2img

excel2img.export_img("snap.xls", "alarm_BB1.png", "Sheet1", "A2:Q20")
excel2img.export_img("snap.xls", "VSWR_BB1.png", "Sheet2", "A2:Q50")
excel2img.export_img("snap.xls", "alarm_BB2.png", "Sheet3", "A2:Q20")
excel2img.export_img("snap.xls", "VSWR_BB2.png", "Sheet4", "A2:Q50")

This works on my system: python 3.6 / Office 2013

I also tried the XLSX files, but these i cannot open, eventually the files are corrupt. excel2img supports XLSX files, i use this module on a project with this extension.

If I use Python 3.7 I get a module error (win32api) and if you look on the project site: there is no support listed for python 3.7 https://pypi.org/project/excel2img/

Try Python 3.6 for your project. On another thread I read that office 2016 can be a problem for excel2img, too. Python's excel2img package not working with MS office 2016

But this i can't test...

I hope this helps you.

Related