源码:
<html>
<head>
<p style="font-size: 20px;color: red;">将json数据导出为csv文件</p>
<button onclick='tableToExcel()'>导出</button>
</head>
<body>
<script>
function tableToExcel(){
//要导出的json数据
var jsonData = [
{
name:'text1',
phone:'123456789',
email:'123@qq.com'
},
{
name:'text2',
phone:'123456789',
email:'123@qq.com'
},
{
name:'text3',
phone:'123456789',
email:'123@qq.com'
},
{
name:'text4',
phone:'123456789',
email:'123@qq.com'
},
]
//列标题,逗号隔开,每一个逗号就是隔开一个单元格
let str = `标题,电话,qq邮箱\n`;
//增加\t为了不让表