json如何输出成excel
[{"ZtdID":"100000","ZtdNo":"001 ","ZtdName":"1号店 ","Address":"XX市ZZ区YY路01号铺 ","Remark":"","AreaID":"01","ZtdTel":"0000-8888888","ZtdContact":"张三"},{"ZtdID":"100001","ZtdNo":"002 ","ZtdName":"1号店 ","Address":"XX市ZZ区YY路01号铺 ","Remark":"","AreaID":"01","ZtdTel":"0000-8888888","ZtdContact":"李三"}]
json解析并输出excel
回复讨论(解决方案)
先格式化成数组,然后可以用一些生成excel的类来生成,比如 http://code.google.com/p/php-excel/
phpexcel 或者其他一些轻量级的插件 生成excel
先把json转回成数据,json_decode
再生成excel,把数组中的输入放入
先格式化成数组,然后可以用一些生成excel的类来生成,比如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":"1号店 ","Address":"XX市ZZ区YY路01号铺 ","Remark":"","AreaID":"01","ZtdTel":"0000-8888888","ZtdContact":"张三"},{"ZtdID":"100001","ZtdNo":"002 ","ZtdName":"1号店 ","Address":"XX市ZZ区YY路01号铺 ","Remark":"","AreaID":"01","ZtdTel":"0000-8888888","ZtdContact":"李三"}]';
$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 1楼,出来成一行了?
header("Content-type: text/html; charset=utf-8");
require 'php-excel.class.php';
$json='[{"ZtdID":"100000","ZtdNo":"001 ","ZtdName":"1号店 ","Address":"XX市ZZ区YY路01号铺 ","Remark":"","AreaID":"01","ZtdTel":"0000-8888888","ZtdContact":"张三"},{"ZtdID":"100001","ZtdNo":"002 ","ZtdName":"1号店 ","Address":"XX市ZZ区YY路01号铺 ","Remark":"","AreaID":"01","ZtdTel":"0000-8888888","ZtdContact":"李三"}]';
$sr = json_decode($json, true);
echo "";
//var_dump($sr);
$headeAarray = array();
$headeAarray[] = array('店铺ID', '店铺编号', '店铺名称', '地址', '标记','区域ID','联系电话','联系人'); //表头二维数组
$dataArray = array();
while($row = ($sr)) {
$dataArray[] = array($row['ZtdID'], $row['ZtdNo'], $row['ZtdName'], $row['Address'], $row['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');
?>
这样还不行,有同学指导一下吗?json 转换下格式,调用NPOI的dll,生成数据流放到excel里,下载下来
下一篇: php中的字符串运算符实例用法汇总
推荐阅读