PHPExcel factory error when reading XML from URL

柔情痞子 提交于 2020-01-06 12:51:41

问题


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:

( ! ) Fatal error: Uncaught exception 'PHPExcel_Reader_Exception' with message ' in C:\wamp\www\project\Classes\PHPExcel\Reader\Excel2007.php on line 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

UPDATE:

$dom = new DOMDocument();
$dom->load($url);
$fileName = 'filename.xml';
$xml = $dom->save($fileName);
$inputFileType = PHPExcel_IOFactory::identify($xml);

( ! )Fatal error: Uncaught exception 'PHPExcel_Reader_Exception' with message 'Could not open 116752 for reading! File does not exist.' in C:\wamp\www\project\Classes\PHPExcel\Reader\Excel2007.php on line 82

( ! ) PHPExcel_Reader_Exception: Could not open 116752 for reading! File does not exist.


回答1:


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 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.

Details of SpreadsheetML can be found here

EDIT

Note also that all PHPExcel Readers expect a filename as their argument, none will accept raw data in any format, or any PHP Objects




回答2:


PHPExcel is to read Excel files, not XML. Try SimpleXML extension.

UPDATE:

So C:\wamp\www\project\Classes\PHPExcel\Reader\Excel2007.php on line 82 says this:

if (!file_exists($pFilename)) {
    throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}

Which means that it expects $pFilename to point on actual file on the filesystem. Try saving your $xml data somewhere and supplying filename to the PHPExcel_IOFactory::identity().



来源:https://stackoverflow.com/questions/23836975/phpexcel-factory-error-when-reading-xml-from-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!