Reading Excel xlsx files in PHP without ZipArchive

2019-06-14 12:43发布

问题:

I am using PHPExcel PHP library for reading xlsx files and every thing is fine. when I am deploying my web application in our server I am facing the below error:

Fatal error: Uncaught exception 'Exception' with message 'ZipArchive library is not enabled'

I know that ZipArchive is a requirement for PHP Excel. and I need to follow the install instructions for it to enable it on my production server.

This error because PHPExcel require the below requirements:

  1. PHP version 5.2.0 or higher
  2. PHP extension php_zip enabled
  3. PHP extension php_xml enabled
  4. PHP extension php_gd2 enabled

Now I cant access our nginx server and cant compile "PHP extension php_zip" then enable it.

my question is:

Is that any Alternatives for PHP_excel dose not require ZipArchive class with PHP extension php_zip enabled ?

I am trying these Alternatives for PHP_excel but all of them based on zip.so compiled and php_zip extension enabled.

Any help will be more than appreciated.

回答1:

Since version 1.8.0, PHPExcel has offered an alternative built-in Zip handler that can be enabled by setting

PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);

before loading any files that are zip-based archives such as xlsx or ods

This is slower and uses more memory than PHP's own ZipArchive extension, but provides an alternative if ZipArchive isn't enabled