我一直在努力阅读我从网页上抓取的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
任何人都可以帮我解决一下吗?
答案 0 :(得分:2)
您的文件存在的问题是,它不仅仅是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"?>
之前的所有内容都被删除
修改强>
它的定义没有Default
样式,这对于SpreadsheetML格式是强制性的......如果你想在第413-417行左右破解Excel2003XML阅读器的代码,请更改< / p>
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();