Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

php - PHPExcel factory error when reading XML from URL

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:wampwwwprojectClassesPHPExcelReaderExcel2007.php on line 82

( ! ) PHPExcel_Reader_Exception: Could not open for reading! File does not exist. in C:wampwwwprojectClassesPHPExcelReaderExcel2007.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:wampwwwprojectClassesPHPExcelReaderExcel2007.php on line 82

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...