问题描述
如何从URL XML数据创建XML阅读器?我提供了从URL到PHPExcel
工厂的identify()
的有效XML数据,但是脚本会触发错误:
How to create XML reader from the URL XML data?I provide valid XML data from a URL to the PHPExcel
factory's identify()
but the script fires an error:
(!)PHPExcel_Reader_Exception:无法打开 读!文件不存在.在 C:\ wamp \ www \ project \ Classes \ PHPExcel \ Reader \ Excel2007.php在第82行
( ! ) PHPExcel_Reader_Exception: Could not open for reading! File does not exist. in C:\wamp\www\project\Classes\PHPExcel\Reader\Excel2007.php on line 82
$url = "http://www.w3schools.com/xml/note.xml";
$xml = simplexml_load_file($url); //OR $xml = simplexml_load_string(file_get_contents($url));
$inputFileType = PHPExcel_IOFactory::identify($xml); // ERROR
更新:
$dom = new DOMDocument();
$dom->load($url);
$fileName = 'filename.xml';
$xml = $dom->save($fileName);
$inputFileType = PHPExcel_IOFactory::identify($xml);
(!)PHPExcel_Reader_Exception:无法打开116752进行读取!文件 不存在.
( ! ) PHPExcel_Reader_Exception: Could not open 116752 for reading! File does not exist.
推荐答案
PHPExcel随附的XML Reader(PHPExcel_Reader_Excel2003XML
)不适用于任何任意XML文件:这将需要极高程度的机器智能来进行解析任意结构的文件到电子表格的确定结构.如果不编写自己的代码,就无法使用通用XML阅读器,该阅读器可以采用任何XML文件结构并将其导入Excel文档而又不了解XML结构.
The XML Reader (PHPExcel_Reader_Excel2003XML
) that is included with PHPExcel isn't for any arbitrary XML file: that would require an incredible degree of machine intelligence to parse a file of arbitrary structure to a the determinate structure of a spreadsheet. A generic XML Reader that can take any structure of XML file and import it into an Excel document without comprehension of the structure of the XML simply isn't possible without writing your own code.
MS Excel 2003
支持称为SpreadsheetML
的格式,该格式是具有定义结构的zip压缩XML文件,并且-尽管该格式很少使用-PHPExcel_Reader_Excel2003XML支持使用该格式编写的电子表格文件. /Examples
文件夹中的XMLReader.php
文件演示了如何读取SpreadsheetML文件.
MS Excel 2003
supported a format called SpreadsheetML
, which was a zip-compressed XML file with a defined structure and - while the format is very rarely used - the PHPExcel_Reader_Excel2003XML provides support for spreadsheet files written using that format. The XMLReader.php
file in the /Examples
folder demonstrates reading a SpreadsheetML file.
可以在此处找到SpreadsheetML的详细信息
Details of SpreadsheetML can be found here
编辑
还请注意, 全部 PHPExcel读者期望文件名作为参数,没有人会接受任何格式的原始数据或任何PHP对象
Note also that all PHPExcel Readers expect a filename as their argument, none will accept raw data in any format, or any PHP Objects
这篇关于从URL读取XML时PHPExcel工厂错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!