<span style="font-size:18px;">exportFile.get = function(req,res){
var fileName = req.query.fileName;
res.set({
'Content-Type': 'application/vnd.ms-execl',
'Content-Disposition': "attachment;filename=" + encodeURIComponent(fileName),
'Pragma': 'no-cache',
'Expires': 0
});
var data = [];
var content = 'username\tage\tsex\t\n';
for(var i=0;i < 10;i++){
var name = "username"+i;
var age = i+10;
var sex = "boy";
content += require("util").format("%s\t,%s\t,%s\t\n",name,age,sex);
}
var buffer = new Buffer(content);
//转换字符集
var iconv = require('iconv-lite');
var str = iconv.encode(buffer, 'gb2312');
res.send(str);
};</span>
nodejs 导出excel
最新推荐文章于 2024-09-01 13:42:23 发布