Class 'ZipArchive' not found error while using PHPExcel - php

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

Related

Ubuntu Apache PHP - Create and write to an Excel Document

I have heard of PHP Excel inorder to work with excel documents in PHP. However do I require MS Office on the Ubuntu System inorder to work and serve excel documents? Or can the PHP Excel extension work ad hoc with serving excel documents in any system?
PHPExcel is pure PHP, it has no requirement to access MS Office in any way
From the readme of the PHPExcel repo on github
PHPExcel is a library written in pure PHP and providing a set of classes that allow you to write to and read from different spreadsheet file formats, like Excel (BIFF) .xls, Excel 2007 (OfficeOpenXML) .xlsx, CSV, Libre/OpenOffice Calc .ods, Gnumeric, PDF, HTML, ... This project is built around Microsoft's OpenXML standard and PHP.
Requirements
PHP version 5.2.0 or higher
PHP extension php_zip enabled (required if you need PHPExcel to handle .xlsx .ods or .gnumeric files)
PHP extension php_xml enabled
PHP extension php_gd2 enabled (optional, but required for exact column width autocalculation)

PHPExcel - locking the file being viewed

I have an excel report which need to be locked from viewing without password authentication. I have tried with following snippets but it's only making it write protect. following is the code snippets I used.
$phpExcelObject->getSecurity()->setLockWindows(true);
$phpExcelObject->getSecurity()->setLockStructure(true);
$phpExcelObject->getSecurity()->setWorkbookPassword("password");
I am using PHPExcel version 1.8.
Seems like this is a know issue with PHPExcel
https://github.com/PHPOffice/PHPExcel/issues/442
Is there any alternative library for this which I can use to make my report password protected?
Thanks.
This isn't an option that PHPExcel supports. If you want to lock a file for reading, then you're very limited in your alternatives. The only libraries that I'm aware of capable of preventing read access to a file without a password are PHP's COM extension, which requires a COM enabled spreadsheet program such as MS Excel or OpenOffice Calc running on the server; the Open Office alternative to COM (PUNO), which requires Open Office installed on the server with Java support enabled; and Ilia Alshanetsky's Excel extension from github, that requires the commercial libXL component installed on your server.

PHP COM (OLE) Object connecting to MS Excel

My setup: IIS 7.5, PHP 5.4, Windows 7
I've trying to create a COM Object through PHP but I continue to get access denied. I've also followed a handful of tutorials on how to "grant access" to the ISUR to create the object but to no avail. I read the installation portion relevant to COM interfacing that says:
As of PHP 5.3.15 / 5.4.5, this extension requires php_com_dotnet.dll
to be enabled inside of php.ini in order to use these functions.
Previous versions of PHP enabled these extensions by default.
You are responsible for installing support for the various COM objects
that you intend to use (such as MS Word); we don't and can't bundle
all of those with PHP.
I've enabled the php_com_dotnet.dll file within the ini file but I still can't seem to create the COM object for Excel. Then if you read the second paragraph it says that you have to install support for the various COM objects you intend to use but doesn't specify how to go about doing that.
Question: How do I install support for the MS Excel COM object?
Any help would be appreciated. I've researched this issue but haven't found very much documentation out there.
Don't do this. You're in for a world of pain trying to launch Excel in a web application, especially from PHP.
Microsoft Office apps such as Word and Excel are not designed for server side use. When you try to instantiate an Excel "COM object" you're spinning up a full instance of Excel as a separate process. That is hugely expensive and will never scale. Not only that, to add to your woes, if for whatever reason your script can't release and shut down Excel you'll end up with tens or possibly hundreds of orphaned Excel processes hanging around in memory.
Try something like: https://github.com/PHPOffice/PHPExcel if you need to read and write Excel compatible spreadsheets.

what is the risk of changing BIFF version in pear excel writer

I am using Spreadsheet_Excel_Writer, which is a component of PEAR, to generate Excel files in a web application.
By default it saves in BIFF5, and I have use setVersion to change the BIFF5 version to BIFF8.
The manual says use of this function will be deprecated. Does anyone know the reason?
It was deprecated because the developers of PEAR Spreadsheet_Excel_Writer always intended to make BIFF8 the default format, and eventually to drop BIFF5 completely as Excel users migrated from Excel95 to Excel98 and later 2003, and the need for backward compatibility with the earlier version was reduced.
However, ongoing development of PEAR Spreadsheet_Excel_Writer atrophied and died before that point was reached; so the interim state remains.
In terms of risk: minimal.
Most of the features of BIFF8 files can still be read by anbody still using Excel95 (the newer features of BIFF8 were never added to Spreadsheet_Excel_Writer); but most Excel users these days have moved on with Excel98 as a minimum version. The newer versions (Excel2007 and Excel2010) can still read BIFF8 files without any problem.

PHPExcel clone .xlsm with macros

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.

Categories