Instance structure:
1. csv2xml.demo.php
<?phpuse Simpleexcel\simpleexcel; This sentence can not be less!require_once ('. /lib/simpleexcel.php '); Import class file $excel = new Simpleexcel (' xml '), $excel->parser->loadfile (' example.csv '); $excel->convertto (' xml ') ; $excel->writer->savefile (' example ');
2. parseXML.demo.php
<?phpuse Simpleexcel\simpleexcel; This sentence can not be less!require_once ('. /lib/simpleexcel.php '); Import class file $excel = new Simpleexcel (' xml '), $excel->parser->loadfile (' example.xml '); $x = $excel->parser->get Field (); Returns a two-dimensional array of all data $ A = $excel->parser->getrow (3); The 3rd line starting from 1 $b = $excel->parser->getcolumn (3); 3rd column starting from 1 $c = $excel->parser->getcell (1, 2); 1th row 2nd Column echo ' <pre> ';p rint_r ($x); Echo ' </pre> ';
3. writeXML.demo.php
<?phpuse Simpleexcel\simpleexcel; This sentence can not be less!require_once ('. /lib/simpleexcel.php '); Import class file $excel = new Simpleexcel (' xml '), $excel->writer->setdata (Array (' ID ', ' Name ', ' kode '), Array (' 1 ', ' Kab. Bogor ', ' 1 '), Array (' 2 ', ' Kab. Cianjur ', ' 1 '), Array (' 3 ', ' Kab. Sukabumi ', ' 1 '), Array (' 4 ', ' Kab. Tasikmalaya ', ' 2 ')); $excel->writer->savefile (' example '); In addition: The method of exporting CSV//In the above code based on modification://1. Modify the 5th behavior: $excel = new Simpleexcel (' CSV ');//2. Add a line before SaveFile: $excel->writer ->setdelimiter (",");
;
PHP read-write CSV, XML file: Simpleexcel