How JSON is exported as Excel

Source: Internet
Author: User
The JSON content is as follows:
[{"Ztdid": "100000", "Ztdno": "001", "Ztdname": "Shop 1th", "Address": "XX City, ZZ District, No. No. 01 yy Road Shop", "Remark": "," Areaid ":" "," Ztdtel ": "0000-8888888", "ztdcontact": "Zhang San"},{"Ztdid": "100001", "Ztdno": "002", "Ztdname": "Shop 1th", "Address": "XX City, ZZ District, No. 01 yy Road Shop", " Remark ":", "Areaid": "," "Ztdtel": "0000-8888888", "ztdcontact": "Lie Triple"}]

JSON parses and outputs Excel


Reply to discussion (solution)

Format the array first, and then you can build it with some classes that generate Excel, such as http://code.google.com/p/php-excel/

Phpexcel or some other lightweight plugin to generate Excel

Turn JSON into data first, Json_decode
Then generate Excel and put the input in the array into

Format the array first, and then you can build it with some classes that generate Excel, such as http://code.google.com/p/php-excel/

Header ("content-type:text/html; Charset=utf-8 ");
Require ' php-excel.class.php ';
$json = ' [{"Ztdid": "100000", "Ztdno": "001", "Ztdname": "Shop 1th", "Address": "XX City, ZZ District, No. 01 yy Road", "Remark": "," Areaid ":" 01 "," Ztdtel ":" 0000-8888888 "," ztdcontact ":" Zhang San "},{" Ztdid ":" 100001 "," Ztdno ":" 002 "," Ztdname ":" Shop 1th "," Address ":" XX City zz Zone yy Road No. 01 Shop "," Remark ":", "Areaid": "", "Ztdtel": "0000-8888888", "ztdcontact": "Lie Triple"}] ';
$SR = Json_decode ($json, true);
echo "

";
Var_dump ($SR);
$data = $SR;

$xls = new Excel_xml (' UTF-8 ', false, ' My Test Sheet ');
$xls->addarray ($data);
$xls->generatexml (' my-test ');
?>

To the 1 floor, out into a row?

Header ("content-type:text/html; Charset=utf-8 ");
Require ' php-excel.class.php ';
$json = ' [{"Ztdid": "100000", "Ztdno": "001", "Ztdname": "Shop 1th", "Address": "XX City, ZZ District, No. 01 yy Road", "Remark": "," Areaid ":" 01 "," Ztdtel ":" 0000-8888888 "," ztdcontact ":" Zhang San "},{" Ztdid ":" 100001 "," Ztdno ":" 002 "," Ztdname ":" Shop 1th "," Address ":" XX City zz Zone yy Road No. 01 Shop "," Remark ":", "Areaid": "", "Ztdtel": "0000-8888888", "ztdcontact": "Lie Triple"}] ';
$SR = Json_decode ($json, true);
echo "

//var_dump ($SR);  

$headeAarray = Array ();
$headeAarray [] = Array (' Store id ', ' Store number ', ' Store name ', ' address ', ' tag ', ' Area ID ', ' Contact phone ', ' contact '); Table header two-dimensional array
$dataArray = Array ();
while ($row = ($SR)) {
$dataArray [] = Array ($row [' Ztdid '], $row [' Ztdno '], $row [' Ztdname '], $row [' Address '], $ro w[' Remark ', $row [' Areaid '], $row [' Ztdtel '], $row [' ztdcontact '];
}
$xls = new Excel_xml (' UTF-8 ', false, ' My Test Sheet ');
$xls->addarray ($headeAarray);
$xls->addarray ($dataArray);
$xls->generatexml (' my-test ');
?>

So not yet, do you have a classmate to guide you?

JSON conversion under format, call Npoi DLL, generate data to be exiled to Excel, download it

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