PHPExcel factory error reading XML from URL

How to create an XML reader from XML data URL? I am providing valid XML data from a URL in PHPExcel factory identify() , but the script is PHPExcel error:

(!) Fatal error: throw exception 'PHPExcel_Reader_Exception' with message 'in C: \ wamp \ www \ project \ Classes \ PHPExcel \ Reader \ Excel2007.php on line 82

(!) PHPExcel_Reader_Exception: could not be opened for reading! The 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: throw exception 'PHPExcel_Reader_Exception' with message 'Could not open 116752 for reading! The file does not exist.' in C: \ wamp \ www \ project \ Classes \ PHPExcel \ Reader \ Excel2007.php on line 82

(!) PHPExcel_Reader_Exception: Failed to open 116752 for reading! file does not exist.

0
source share
2 answers

The XML Reader ( PHPExcel_Reader_Excel2003XML ), which is part of PHPExcel, is not intended for any arbitrary XML file: this requires an incredible degree of machine intelligence to analyze an arbitrary structure file for a specific spreadsheet structure. A general XML Reader, which can accept any structure of an XML file and import it into an Excel document without understanding the XML structure, is simply not possible without writing your own code.

MS Excel 2003 supported a format called SpreadsheetML , which was a zip-compressed XML file with a specific structure and - although the format is very rarely used, PHPExcel_Reader_Excel2003XML provides support for spreadsheet files written using this format. The XMLReader.php file in the /Examples demonstrates reading the SpreadsheetML file.

SpreadsheetML details can be found here.

EDIT

Please note that all PHPExcel readers expect the file name as their argument, none of them will accept raw data in any format or any PHP objects

+2
source

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

UPDATE

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

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

This means that it expects $pFilename indicate the actual file in the file system. Try saving the $xml data somewhere and put the file name in PHPExcel_IOFactory::identity() .

+1
source

Source: https://habr.com/ru/post/975707/


All Articles