PHPExcel clone .xlsm with macros

2020-02-07 02:21发布

问题:

I'm trying to read, clone and write and .xlsm file with PHPExcel but I get an error: Fatal error: Uncaught exception 'Exception' with message 'Worksheet!G177 -> Formula Error: An unexpected error occured' in...

Anybody know how can I read, clone and write and Excel file with macros, I mean the macros are in a template (the file that I reading) I just want to clone that file and write on it, and just keep the macros in the new file. Is that possible with PHPExcel ? is there another library to do that ?

Thanks .

回答1:

First:

  • PHPExcel does not support reading Excel macro (.xlsm) files.

Second:

  • it doesn't support macros.

And I'm not aware of any PHP libraries that support this.

The only way that I know for certain that you could do this would be using PHPs COM extension, on a server with MS Excel itself installed.

The only alternative to COM that may work would be Ilia Alshanetsky's Excel extension



回答2:

This thread is a little old, but I had the same issue where I needed to modify Excel files with macros from PHP. No PHP librairy that I know support edit Excel files without negatively impacting the macros.

However the LibXL library supports the preservation of macros as of version 3.3.1. It's not written in PHP, but what we ended up doing is to write our Excel editing in C++ and we called that c++ program from PHP via the exec() method. It worked very well and had very good performance. Hope it helps somebody.



标签: php phpexcel