当使用excel2img
库来捕捉一张纸的特定部分时,出现以下错误。
AttributeError: '<win32com.gen_py.Microsoft Excel 16.0 Object Library.Range instance at 0x2697515534376>' object has no attribute 'parent'
第一次使用相同的代码即可。但此后它停止了工作。只是为了说明,我使用的是与以前相同的Office版本,在这之间所做的唯一更改是我安装了几个库。我不知道是否是由于这个原因。
我试图将excel版本.xlsx
从更改为.xls
。但是然后它返回错误
"OSError: Failed to open snap.xlsx".
下面是我正在使用的代码:
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")
以下是我得到的错误:
AttributeError: '<win32com.gen_py.Microsoft Excel 16.0 Object
Library.Range instance at 0x2697515188064>' object has no attribute
'parent'
下面是快照excel file.bothxls
和xlsx
格式。snap.xlsx
通过使用XLS文件:
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")
这适用于我的系统:python 3.6 / Office 2013
我也尝试了XLSX文件,但这些我无法打开,最终文件损坏了。excel2img支持XLSX文件,我在具有此扩展名的项目中使用此模块。
如果我使用Python 3.7,则会收到模块错误(win32api),并且如果您在项目站点上查看:python 3.7没有列出支持https://pypi.org/project/excel2img/
在您的项目中尝试使用Python 3.6。在另一个线程上,我读到Office 2016可能也是excel2img的问题。Python的excel2img软件包不适用于MS Office 2016
但这我无法测试...
我希望这可以帮助你。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句