var newData = [
{
gameName:"test",
user:"test",
downloadTime:'2020'
}
];
// 导出csv
const fileName = "gcloudDownLoadInfo.xls";
res.set({
"Content-Type": "application/vnd.ms-execl",
"Content-Disposition": `attachment;filename=${encodeURIComponent(fileName)}`,
Pragma: "no-cache",
Expires: 0
});
let content = "";
content += "游戏名称";
content += "\t";
content += "下载人";
content += "\t";
content += "下载时间";
content += "\t";
content += "\t\n";
for (let i = 0, len = newData.length; i < len; i++) {
content += newData[i].gameName;
content += "\t";
content += newData[i].user;
content += "\t";
content += newData[i].downloadTime;
content += "\t";
content += "\t\n";
}
const buffer = new Buffer(content);
// 需要转换字符集
const iconv = require("iconv-lite");
const str = iconv.encode(buffer, "gb2312");
res.send(str);
node导出excel
最新推荐文章于 2024-06-26 22:07:25 发布