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 .
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
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.
Related
I need to find a PHP library that reads/previews Excel files uploaded by a user.
Does anyone know of any PHP Libraries used to parse .xsls files?
Have you tried phpexcel?
Great documentation and open source library.
When I use PHPExcel on a new server,
I faced the error "Class 'ZipArchive' not found" and it seems to be blocked by my hosting service provider.
Can't I use PHPExcel on the server without Zip support?
PHP 5.2.8 is installed on this server but I can't use a basic PHP source code for PHPExcel.
Any help will be appreciated,
thanks.
Certain spreadsheet file formats, such as OfficeOpenXML used as the default format by Excel 2007 and above, require ZipArchive. In most recent versions of PHP, ZipArchive is always available, but prior to PHP 5.3 it needed to be manually installed on some systems as a PHP extension.
If you don't have ZipArchive installed/enabled for your PHP, and can't enable it yourself, then you can use
PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);
PCLZip is included in the PHPExcel distribution as an alternative to PHP's built-in ZipArchive class, though it is quite a bit slower. Enabling PCLZip allows you to work with zip-based spreadsheet formats even without ZipArchive.
However, when we first bundled PCLZip (originally in PHPExcel 1.7.6), it was only an option when writing zip-based formats, not when reading them. We changed that in PHPExcel 1.8.0, so enabling PCLZip now allows you to read zip-based formats as well as writing them.
The PHPEXcel Reader documentation details the different spreadsheet formats, and explains which ones are zip-based.
PHPEXcel Reader documentation
I need to manipulate XLS files from PHP.
I found the great library PHPExcel which does 99% all of the job I need. Sadly I miss that 1%, which is writing the name of the "Creating application" (gnumeric sees it as meta:generator) in Excel 2007 files (Excel5 as called in the library).
Is there any other way to write this tag?
I can work around this by converting the XLS to gnumeric (using ssconvert), adding the tag to the XML file and convert back to XLS, but since I should use this script in a headless server I'd rather avoid installing gnumeric.
Any help is appreciated, even if another method exists (a command line tool, another PHP library).
I develop webapp with PHP5 to read or to actualize xlsm files.
I have tried with PHPEXCEL, but this library not supported xlsm-files format.
Everything what I need, is open the file, write the data in there and stores as a xlsm-file.
The macro should not be changed.
It is important that the file returns which contains the macros because this file it is used daily to do several import. I may not change the file-format.
if somebody has tips or tutor's courses for this specific task has, please writes to me.
Thanks 4 your help
If you need to retain macros from an Excel template, then you'll need to use something like COM because there aren't any other libraries that handle macros from PHP
xslm files are actually ZIP files with XML documents and other assets inside them. PHPEXCEL and other similar MS Office file format readers and writers only read the older binary-blob formats, not the newer Office Open XML formats.
Try using ZipArchive to open the file in PHP, and one of the PHP XML libraries to read the xml inside the file. As long as you don't alter the macros, the macros will be preserved.
However, if you actually need to execute the macros, you need a full Office runtime. In this case you must use COM on windows with a copy of Office to run the file.
My application generates some .xls files and until now I was using PHPExcel lib. One of the SO has recommend me to use this approach. The problem is that I have to use some .xls templates and to append some data to them.
Who can help me with some pointers. I don't get how xlsBOF() and xlsEOF() works or have to work in my case.
If the approach you use right now works for you, don't bother with anything else.
PHPExcel writes XML files (or more accurately zip files containing XML files), in the new Excel 2007 format. For this reason, it's not compatible with older office versions (unless you install the compatibility plugin in the older office).
What this code does is write a binary XLS file in Excel 97 (BIFF8) format. It's a bit of a hack though. This won't deal correctly with unicode issues and so on. xlsBOF writes the binary header of the XLS file, and xlsEOF the footer.
If you want to write binary XLS files, you're better off using PEAR Excel Writer. I have mixed experiences with that. It gets the job done, but to use it with unicode you have to look through the bug list for a few patches that fix BIFF8 format bugs (the package is poorly maintained). It's still better than the code you linked to though.
Update: PHPExcel supports export as Excel 97 also. I remember that it used to be limited to the office 2007 file format, but apparently currently it's not. So I would recommend using PHPExcel.