I have been using openpyxl 3.0.9 from some time. Yesterday, I open a workbook, set a few cells and save it. Since yesterday, the saved workbook cannot be opened by Excel. I have not changed my software or the version of openpyxl. I don't believe my version of Excel has changed (Microsoft® Excel® for Microsoft 365 MSO (16.0.14326.20850) 64-bit). The problem occurs with different workbooks including ones that worked before yesterday. When I look inside the XLSX archive, every file in the openpyxl saved XLSX is omitting a good deal that was in the original. I created a very simple test case that fails, a workbook with three named ranges. I open the workbook, set the three named cells to 5, 7, and 9 respectively and then save. The saved workbook cannot be opened in Excel. I have attached both. [N.B. openpyxl is issuing the warning "... \site-packages\openpyxl\comments\shape_writer.py:74: FutureWarning: The behavior of this method will change in future versions. Use specific 'len(elem)' or 'elem is not None' test instead." but it has been doing this for some time and still working.]
--
You received this message because you are subscribed to the Google Groups "openpyxl-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openpyxl-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/openpyxl-users/cbb62fe0-e82c-4145-9240-cf4072bee387n%40googlegroups.com.
On 14 Apr 2022, at 21:54, Nmhor Kmhor wrote:
Thanks Charlie. In creating a simple sample to submit a bug, I discovered
the cause. I had keep_vba=True when loading the workbook. I've had that
flag set for some time. I don't know why it started failing now (on
workbooks with no VBA). For my immediate use case, all of the workbooks I
am writing are guaranteed not to have macros so I removed the flag.
For reasons best known to themselves, Microsoft requires a separate content type for workbooks with macros and this is set by the flag. You must have this and ".xlsm" in the file name otherwise Excel won't be open the file.
Things will change in openpyxl 3.2 which has completely rewritten support for VBA and will let you decide by file extension.