glexey / excel2img

Save ranges from Excel documents as images
Apache License 2.0
98 stars 26 forks source link

Object has no attribute 'parent' #14

Open Hyperrick opened 3 years ago

Hyperrick commented 3 years ago

I am currently working on a Python script that saves screenshots from an Excel file using the excel2image module.

My code is pretty easy:

import excel2img excel2img.export_img(Workpath + "/" + "CB_TEMP.xlsx", "alarm_BB1.png", "Deckblatt", "A2:C20")

Unfortunately I always get the following error message:

`Unfortunately I always get the following error message:


AttributeError Traceback (most recent call last)

in ----> 1 excel2img.export_img(Workpath + "/" + "CB_TEMP.xlsx", "alarm_BB1.png", "Deckblatt", "A2:C20") ~\anaconda3\lib\site-packages\excel2img\excel2img.py in export_img(fn_excel, fn_image, page, _range) 111 112 # See http://stackoverflow.com/a/42465354/1924207 --> 113 for shape in rng.parent.Shapes: pass 114 115 xlScreen, xlPrinter = 1, 2 ~\anaconda3\lib\site-packages\win32com\client\__init__.py in __getattr__(self, attr) 471 args=self._prop_map_get_.get(attr) 472 if args is None: --> 473 raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr)) 474 return self._ApplyTypes_(*args) 475 AttributeError: '' object has no attribute 'parent'` I have already tried several workarounds but I can't get it to work. Sometimes it works like magic, but mostly only after a reboot and deleting the data in C:/Users/patrick/AppData/Temp/gen_py. I have a feeling something is clashing in the code with the win32com module I use in a function before to convert an XLSB file to an XLSX file: `def ConvertExcel(excel_filepath, Workpath): excel = win32com.client.gencache.EnsureDispatch('Excel.Application') xlsb_doc = excel.Workbooks.Open(os.path.abspath(excel_filepath)) excel_sheets = os.path.abspath(Workpath) + "\\CB_TEMP.xlsx" xlsb_doc.SaveAs(excel_sheets, 51) xlsb_doc.Close() excel.Quit() del excel return excel_sheets` Kind regards, Patrick
amfor commented 3 years ago

Hey Patrick,

Feel free to try using my fork here. It turns out the parent attribute changed for parent to Parent, so this was a simple one-line fix.

DustinCChen commented 2 years ago

Hey Patrick,

Feel free to try using my fork here. It turns out the parent attribute changed for parent to Parent, so this was a simple one-line fix.

settled,thanks!

kkjzio commented 4 months ago

Hey Patrick,

Feel free to try using my fork here. It turns out the parent attribute changed for parent to Parent, so this was a simple one-line fix.

you save me a night thx!

kevinbarzola-zest commented 3 months ago

Thnks

Hey Patrick,

Feel free to try using my fork here. It turns out the parent attribute changed for parent to Parent, so this was a simple one-line fix.

It worked for me