安装好PHPExcel,能够使用composer安装;php
第一个错误是phpzip库没有找到,ZipArchive and lib-zip.dll
PHPExcel 依赖 lib_zip库,须要在PHP的php.conf文件中打开。PHP5.3+默认有这个库,可是XAMPP TMD竟然没有。要看有没有能够打开 XAMPP_ROOT/php/ext/ (in Windows) 文件夹看有没有 lib_zip.dll;
若是没有能够从 官网 下载,拖到 lib_zip.dll 上面的文件夹中。but,好像不行,须要从新编译PHP。git
PHPExcel内置的zip库 PCLZIP
phpexcel 有一个 Pclzip 类,做为 lib_zip 缺失的状况下的备胎,具体能够看( from stackoverflow )
须要在加载IOFactory
方法前 添加一句PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);
来切换到内置的zip库。github
路径有问题 Classes/Shared/ZipArchive.php
可是内置的 Classes/Shared/ZipArchive.php 类有个不兼容Windows路径的错误须要更正一下,在方法 public function getFromName($fileName)
(141行)。
找到的错误是传进来的 $fileName
包含的路径是这样的の xl/_rels/workbook.xml.rels
(即便在windows下也是斜线模式,*nix)可是实际在 $list
数组中的倒是Windows的反斜线风格 xl\_rels\workbook.xml.rels
,斜线和反斜线不匹配,So 问题来了。
须要在匹配的if判断中添加反斜线的匹配!!!!!!!!!!!!!windows
# before if (strtolower($list[$i]["filename"]) == strtolower($fileName) || strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) { # after if (strtolower($list[$i]["filename"]) == strtolower($fileName) || str_replace("/", "\u{5c}", strtolower($fileName)) == strtolower($list[$i]["filename"]) || strtolower($list[$i]["stored_filename"]) == strtolower($fileName) || str_replace("/", "\u{5c}", strtolower($fileName)) == strtolower($list[$i]["stored_filename"])) { # \u{5c} is backslash
还会有一个问题就是 "**Variable contents is not defined
", so 再小改一下数组
# before if ( is_array($extracted) && $extracted > 0 ) { $contents = $extracted[0]["content"]; } return $contents; #after $contents = ""; if ( is_array($extracted) && $extracted > 0 ) { $contents = $extracted[0]["content"]; return $contents; } return false;
如今能够在PHP7(Windows)中使用了composer