Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel clone .xlsm with macros

Tags:

php

phpexcel

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 .

like image 939
dtrejogo Avatar asked May 06 '11 15:05

dtrejogo


2 Answers

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

like image 111
Mark Baker Avatar answered Oct 23 '22 22:10

Mark Baker


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.

like image 4
Mart Coul Avatar answered Oct 23 '22 20:10

Mart Coul