How to output json to excel

Source: Internet
Author: User
How to output json into excel json:
[{"ZtdID": "100000", "ZtdNo": "001", "ZtdName": "Shop 1", "Address ": "Shop No. 01, YY Road, ZZ district, XX city", "Remark": "", "AreaID": "01", "ZtdTel": "0000-8888888 ", "ZtdContact": "Zhangsan" },{ "ZtdID": "100001", "ZtdNo": "002", "ZtdName": "Shop 1", "Address ": "Shop No. 01, YY Road, ZZ district, XX city", "Remark": "", "AreaID": "01", "ZtdTel": "0000-8888888 ", "ZtdContact": "Li San"}]

Json parsing and excel output


Reply to discussion (solution)

First formatted into an array, and then can be generated with some generated excel class, such as http://code.google.com/p/php-excel/

Phpexcel or some other lightweight plug-ins to generate excel

Convert json back to data, json_decode
Generate an excel file and put the input in the array

First formatted into an array, and then can be generated with some generated excel class, 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 1", "Address ": "Shop No. 01, YY Road, ZZ district, XX city", "Remark": "", "AreaID": "01", "ZtdTel": "0000-8888888 ", "ZtdContact": "Zhangsan" },{ "ZtdID": "100001", "ZtdNo": "002", "ZtdName": "Shop 1", "Address ": "Shop No. 01, YY Road, ZZ district, XX city", "Remark": "", "AreaID": "01", "ZtdTel": "0000-8888888 ", "ZtdContact": "Li San"}] ';
$ 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 first floor. Is it a line?

Header ("Content-type: text/html; charset = utf-8 ");
Require 'php-excel. class. php ';
$ Json = '[{"ZtdID": "100000", "ZtdNo": "001", "ZtdName": "Shop 1", "Address ": "Shop No. 01, YY Road, ZZ district, XX city", "Remark": "", "AreaID": "01", "ZtdTel": "0000-8888888 ", "ZtdContact": "Zhangsan" },{ "ZtdID": "100001", "ZtdNo": "002", "ZtdName": "Shop 1", "Address ": "Shop No. 01, YY Road, ZZ district, XX city", "Remark": "", "AreaID": "01", "ZtdTel": "0000-8888888 ", "ZtdContact": "Li San"}] ';
$ Sr = json_decode ($ json, true );
Echo"

";
// Var_dump ($ sr );

$ HeadeAarray = array ();
$ HeadeAarray [] = array ('shop ID', 'shop number', 'shop name', 'address', 'tag', 'region ID', 'Contact number ', 'contacts '); // Two-dimensional array of the header
$ DataArray = array ();
While ($ row = ($ sr )){
$ DataArray [] = array ($ row ['ztdid'], $ row ['ztdno'], $ row ['ztdname'], $ row ['address'], $ row ['remark'], $ row ['aread'], $ row ['ztdtel '], $ row ['ztdcontact']);
}
$ Xls = new Excel_XML ('utf-8', false, 'My Test Sheet ');
$ Xls-> addArray ($ headeAarray );
$ Xls-> addArray ($ dataArray );
$ Xls-> generateXML ('My-test ');
?>

This is not enough. Can someone give me some guidance?

In json format, call NPOI dll to generate a data stream and put it in 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.