theorchard / openpyxl

Other
54 stars 21 forks source link

Code signing certificate lost when saving file #28

Open skywalker-sr opened 1 year ago

skywalker-sr commented 1 year ago

I'm using openpyxl to generate vba-enabled spreadsheets and it has been working a treat. I simply have a base xlsm file which I then populate with the relevant customer's data and load it with the keep_vba=True option.

In getting ready to push this out to our customers I've just stumbled across the fact that the certificate we use to code sign our macros is getting lost when openpyxl saves the document. The code signing process adds about 50KB to the file, which is still present in the size of the final file, even though excel no longer considers it to be signed - so I'm hoping that this might be a fairly straightforward fix.

The only thing I can find out there is this post from several years ago: https://foss.heptapod.net/openpyxl/openpyxl/-/issues/869, where the author wasn't particularly helpful with examples so the team couldn't reproduce it. The author did point out however that

Excel adds "\xl_rels\vbaProject.bin.rels" in the archive during adding of the signature. A rule for this file is absent in _merge_vba that's why the digital signature is lost.

Which sounds as though it might be on the right track.

I appreciate that support for macros is provided on a best-efforts basis, but being able to generate code signed, macro-enabled excel documents is incredibly valuable. I'm happy to help with this in any way I can in terms of examples and even code if needed.

Thanks guys - really appreciate all you do!

skywalker-sr commented 1 year ago

I noticed that there was more action on heptapod so posted a more detailed version of this over there with specific example files: https://foss.heptapod.net/openpyxl/openpyxl/-/issues/1997