Open blairfrandeen opened 1 year ago
Here is a workbook that will cause the crash described above. Part of what causes this may be having named ranges in the workbook. workbook.xlsx
yes, this sounds more like an issue you should open with openpyxl. If you can reproduce this issue when doing the same action manually, it's definitely nothing to do with xlwings.
OS Windows 10 Enterprise 22H2
Versions of xlwings, Excel and Python (e.g. 0.11.8, Office 365, Python 3.7)
Describe your issue (incl. Traceback!)
When trying to use
worksheet.pictures.add(filepath)
on a workbook that has had sheets copied and moved using openpyxl, xlwings crashes with the following stack trace:Include a minimal code sample to reproduce the issue (and attach a sample workbook if required!)
Start with a workbook that has some hidden sheets. Execute the following code in openpyxl:
Then execute the following using xlwings:
Note that I can't fully reproduce the issue with the code above - there is something about the template I'm using (which I'm unable to share) that may be part of the root of the problem.
Investigation & workaround.
I believe that this bug originates in openpyxl. However, the workaround I did works in xlwings. Simply un-hiding and re-hiding all of the worksheets seems to fix the problem:
My guess is that somehow openpyxl screws up the sheet indexing. Adding a simple operation like what's above to
worksheet.pictures.add()
may be a good safety measure to avoid the crash that I'm getting.