无法读取Excel 97-2004工作簿



我一直在努力阅读从网页上抓取的Excel文件。它的类型是:Microsoft Excel 97-2004工作簿(我从MS Excel中查看了它)。这就是我正在尝试的PHPExcel:

$destination = APPPATH . "docs/app.xls";
$inputFileType = PHPExcel_IOFactory::identify($destination);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($destination);

我得到以下错误:

A PHP Error was encountered
Severity: Warning
Message: simplexml_load_file(): /var/www/application/cookies/app.xls:1: parser error : Start tag expected, '<' not found
Filename: Reader/Excel2003XML.php
Line Number: 333
....
A PHP Error was encountered
Severity: Warning
Message: simplexml_load_file(): HTTP/1.1 200 OK
Filename: Reader/Excel2003XML.php
Line Number: 333
...
A PHP Error was encountered
Severity: Warning
Message: simplexml_load_file(): ^
Filename: Reader/Excel2003XML.php
Line Number: 333
...
Fatal error: Call to a member function getNamespaces() on boolean in /var/www/application/third_party/PHPExcel/Reader/Excel2003XML.php on line 334
A PHP Error was encountered
Severity: Error
Message: Call to a member function getNamespaces() on boolean

有人能帮我解决吗?

文件的问题在于它不仅仅是SpreadsheetML格式,它已经损坏。

在文本编辑器中打开文件,我可以看到http响应标头也包含在文件中

HTTP/1.1 200 OK
Date: Fri, 13 Nov 2015 09:55:31 GMT
Server: Apache-Coyote/1.1
Content-Disposition: inline; filename="sdp_daily_app_revenue_report.xls"
Content-Type: application/vnd.ms-excel
Transfer-Encoding: chunked
<?xml version="1.0" encoding="UTF-8"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
....
</Workbook>

这使得它无法阅读。。。。。该文件应该只包含实际的xml内容

我不知道你是如何获得它的,但你需要确保http响应头不会被回显到文件中。如果<?xml version="1.0" encoding="UTF-8"?>之前的所有内容都被剥离,PHPExcel应该毫无问题地读取它

编辑

它也没有定义Default样式,这对于SpreadsheetML格式是强制性的。。。。如果您想在413-417行左右破解Excel2003XML阅读器的代码,请更改

if ($styleID == 'Default') {
    $this->styles['Default'] = array();
} else {
    $this->styles[$styleID] = $this->styles['Default'];
}

$this->styles[$styleID] = (isset($this->styles['Default'])) ? $this->styles['Default'] : array();

最新更新