Rahul R Badenkal
Rahul R Badenkal

Reputation: 81

Adding macros script to an excel file externally in Linux

My requirement is: I have been given an excel (the user uploads it to our server) and then my program should automatically add a macros code (defined in a text file maybe) to the excel file and then send it back to the user. I found a similar question but the solution only works in Windows but since our server is Linux based, I haven't found a way to do so.

Link to the similar question: Use Python to Inject Macros into Spreadsheets

Upvotes: 2

Views: 867

Answers (1)

ThunderFrame
ThunderFrame

Reputation: 9461

Assuming you're being sent a file in xlsm format, you need to following capabilities:

  1. Open the file as a zip file
  2. Locate the .bin part path from the rels files - see Microsoft Open Packaging Conventions
  3. Locate and open the VBA project's .bin stream
  4. parse the .bin stream as a Compound Binary File Format file
  5. Parse the binary streams that describe and list the module contents of the file, as documented in Office VBA File Format Structure
  6. Add your module text as a new stream, and update the files from step 5 with the new contents.

It's not a small undertaking. The work has already been done in Python, and a lot of the libraries for working with zip files and compound binary format files are already in .NET for Windows. Otherwise, as far as I'm aware, there aren't any other pre-built tools, other than the tools from aspose

Upvotes: 1

Related Questions