java的json导出excel_几种前端json导出excel方法

$(document).ready(function(){

$('#wwo').click(function(){//测试的json数据

vardata3=[{"id":10000,"username":"user-0","sex":"女","city":"城市-0","sign":"签名-0","experience":255,"logins":24},

{"id":10001,"username":"user-1","sex":"男","city":"城市-1","sign":"签名-1","experience":884,"logins":58} ,

{"id":10002,"username":"user-2","sex":"女","city":"城市-2","sign":"签名-2","experience":650,"logins":77}]//自定义标题栏

vartitle=['用户名','性别','城市','签名','经验']//自定义过滤栏(不需要导出的行)

varfilter=['id','logins']//原始导出

JSONToExcelConvertor(data3,"report");//自定义导出

//JSONToExcelConvertor(data3,"report",title,filter);

});

});

function JSONToExcelConvertor(JSONData, FileName,title,filter) {

if(!JSONData)

return;

//转化json为object

var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;

var excel = "

//设置表头

var row = "

";

if(title)

{

//使用标题项

for (var i in title) {

row += "" + title[i] + '';

}

}

else{

//不使用标题项

for (var i in arrData[0]) {

row += "" + i + '';

}

}

excel += row + "

";

//设置数据

for (var i = 0; i

var row= "

";

for (var index in arrData[i]) {

//判断是否有过滤行

if(filter)

{

if(filter.indexOf(index)==-1){

var value= arrData[i][index] ==null ? "" : arrData[i][index];

row += '

' + value + '';

}

}

else

{

var value = arrData[i][index] == null ? "" : arrData[i][index];

row += "" + value + "";

}

}

excel += row + "

";

}

excel += "

";

var excelFile = "";

excelFile += '';

excelFile += '

excelFile += '; charset=UTF-8">';

excelFile += "

";

excelFile += "";

excelFile += "";

excelFile += "

";

excelFile += excel;

excelFile += "";

excelFile += "

你可能感兴趣的:(java的json导出excel_几种前端json导出excel方法)