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.