[jQuery] json 데이터를 엑셀(CSV)로 익스포트
Convert JSON format to CSV format for MS Excel [closed]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JSON to CSV</title>
<script src="scripts/json.js" type="text/javascript"></script>
<script type="text/javascript">
var json3 = { "d": "[{\"Id\":1,\"UserName\":\"Sam Smith\"},{\"Id\":2,\"UserName\":\"Fred Frankly\"},{\"Id\":1,\"UserName\":\"Zachary Zupers\"}]" }
DownloadJSON2CSV(json3.d);
function DownloadJSON2CSV(objArray)
{
var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
var str = '';
for (var i = 0; i < array.length; i++) {
var line = '';
for (var index in array[i]) {
line += array[i][index] + ',';
}
// Here is an example where you would wrap the values in double quotes
// for (var index in array[i]) {
// line += '"' + array[i][index] + '",';
// }
line.slice(0,line.Length-1);
str += line + '\r\n';
}
window.open( "data:text/csv;charset=utf-8," + escape(str))
}
</script>
</head>
<body>
<h1>This page does nothing....</h1>
</body>
</html>
원본 위치 <http://stackoverflow.com/questions/4130849/convert-json-format-to-csv-format-for-ms-excel>
'Web > javascript / jQuery' 카테고리의 다른 글
[jquery] 날짜 계산 (10) | 2015.04.28 |
---|---|
[jquery] HTML 새창으로 열기 (780) | 2015.04.28 |
[jQuery] ctrl + c, ctrl + v 등이 작동하도록 단축키 만들기 (311) | 2015.04.28 |
[jQuery] 날짜 계산 (예/1주일전) (1143) | 2015.04.28 |
jquery context menu 데모 (821) | 2015.04.28 |