I need to use openpyxl and embedded python scripts/macros (tq APSO) so I choose xlsm format as ‘save file type’, but when I save my file, all my macros and control buttons etc vanished. The ods version from where the macros’s come from work perfectly and I wish I could stick with that, but as I said, I need to use openpyxl. How to save the xlsm file so that it preserves these macros and buttons etc? It seems very odd that LO offers xlsm but then destroys and all effort done in macro work and form design. I’m using Linux Mint 20.3 and LO 7.3.4.2
You should blame MS, and its format.
“LO offers xlsm” not to suggest you that is allows whatever you could think it does, but for interoperability: the format is expected to interoperate with MS Excel. To achieve that, we need to know how to store different features in the format. And when there is no documentation available on that, we at least need example documents. Otherwise, there is the highest risk to create an alternative implementation, producing documents that nothing except LibreOffice can read.
Please provide an XLSM created by MS Excel, with Python macros inside, so that we could learn how to embed the Python macros there properly.
Having said that: we even don’t yet support creating VBA modules anew; current VBA module support (in any format) relies on opening a document already containing a VBA module (so originally coming from a MS format).
It not your question, but why do you need openpyxl? Is this the single implementation to access spreadsheet data, or driven by other code? Could you export your data to xls/x/m and keep buttons and macros in your ods?
.
Compare it to .xls: You will be told all lines beyond the capabilities of xls will be cut of. So in your line of thinking LibreOffice should not export to xls, as xls is not capable to handle bigger sheets of LO ?? I’ll be surprised, if MS documented python scripts for xlsm-Files, but ok - I never tried.
Hi mikekaganski.
I think if MS doesn’t publish info on how LO can “support” xlsm , then it would be kind for LO to make it clear whenever the spectre of an xlsm file arises, that a warning is generated e.g. “Warning: LO’s support for xlsm is limited. Currently no macros or control elements can be retained or saved with this format” or simply not even bother to tempt people into this black hole with no clear-cut guidelines as to what they can do.
I coded my macros and control elements in LO Calc and then I needed to use openpyxl. That’s when I saved my calc file as .xlsm. I have already achieved everything I want in Excel and VBA but I have decided to wave goodbye to MS, so I don’t have an xlsm created by Excel.
It’s understandable that there are ‘issues’ with VBA support in LO (although clearer warning on this for the unsuspecting would be appreciated too) hence I went the python to try and alleviate that.
So there’s no way I can ‘export’ my macro ods file into an xlsm enabling me to use openpyxl?
Hi Wanderer.
There’s a few reasons I’ll need to use openpyxl. The most simple of them is for my Calc files to be compatible with users who cannot think beyond the world of Excel. It’s more than just a matter of data, it’s the “in spreadsheet, control-elements / forms / processing / user interactivity” that’s important.
I know about 6 months back MS said they’d support “open document” standards but for many reasons I really don’t want to keep using their OS & Suites (I can live with their xls/x/m file format). My line of thinking was purely that if LO Calc offers xlsm then it surely it should be able to do it - all I need to know is how.
Hi elmau. I see your point, but that wouldn’t bring me any further forward.
Sorry for cutting in.
I saw you on Youtube/LibreOffice Hispano explaining in the video of “Extender LibreOffice con Python”.
That is very difficult for me even though I read the English caption.
Are there any simple lessons of Python for LibreOffice ?
Have you disabled that warning yourself?
No there is none.
Then you can’t expect any features not supported by Excel (like Python macros) in any files you create. So you made a mistake even before starting to save to XLSM
You’ve got to know:
- Python fairly well
- LibreOffice very well
Then you will understand the technical documentation without any problems. No, there are no simple lessons for complex issues.
I did not get that warning! I tried it again (saving from ods) and again, no warning. I’ve no idea why or how.
“No there is none.”
- OK. Thanks for confirming, but it’s such a shame
Then you can’t expect any features not supported by Excel (like Python macros) in any files you create. So you made a mistake even before starting to save to XLSM
- Interesting, given there’s quite a bit of web-stuff about combing the two on the web. Well even if you’re right, the fallback of running python scripts to “impregnate” Excel via Openpyxl is ever present.
Villeroy, your reply to lonk is somewhat circular and not helpful.
Besides, the documentation is too technobabbled for beginners.
This site however does an excellent job at trying to educate people trying to step-up
https://tutolibro.tech/
This is for professional programmers.
Indeed. Looks like beginners will have to rely on the charity of the outer community. Pity the aura of ‘give it a go’ and tutorials are orders of magnitude more muted than other packages.
another Series of the kind Howto NOT todo
Couldn’t decipher that.
If you’re actually curious, it meant as a reserve option I can manipulate Excel via Openpyxl.
another Series of the kind Howto NOT todo
I disagree. That site has been quite helpful. Do you know of any better sites?
Don’t know if better or worse, but there’s a small collection at LibreOffice Python Scripting. (and yes I just added that tutolibro site there as well without knowing whether it’s good, bad, or ugly).