无法读取Excel 97-2004工作簿

我一直在努力阅读从网页上抓取的Excel文件。 它有这样的types: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格式定义….如果你想破解Excel2003XML阅读器的代码绕413-417行,改变

 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();