PHP read-write CSV, XML file: Simpleexcel

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.