Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object has no attribute 'parent' #14

Open
Hyperrick opened this issue Mar 20, 2021 · 2 comments
Open

Object has no attribute 'parent' #14

Hyperrick opened this issue Mar 20, 2021 · 2 comments

Comments

@Hyperrick
Copy link

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: '<win32com.gen_py.Microsoft Excel 16.0 Object Library.Range instance at 0x2460934736048>' 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
Copy link

amfor commented Jun 5, 2021

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
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants