大更新

This commit is contained in:
weicw
2021-11-04 22:30:40 +08:00
parent e3b8cafdac
commit 18f4bd8a4d
45 changed files with 1447 additions and 16807 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,43 @@
const exportTableData = function(columns,data){rt
const ExcelJS = require('exceljs');
const exportTableData = function(columns,data){
return columns + data
}
const downloadTemplate = function (name){
var a = document.createElement("a"); //创建一个<a></a>标签
a.href = `/template/${name}.xlsx`; // 给a标签的href属性值加上地址注意这里是绝对路径不用加 点.
a.download = `${name}-导入模板.xlsx`; //设置下载文件文件名,这里加上.xlsx指定文件类型pdf文件就指定.fpd即可
a.style.display = "none"; // 障眼法藏起来a标签
document.body.appendChild(a); // 将a标签追加到文档对象中
a.click(); // 模拟点击了a标签会触发a标签的href的读取浏览器就会自动下载了
a.remove(); // 一次性的用完就删除a标签
}
const excelToJson = async function (buffer){
const wb = new ExcelJS.Workbook();
await wb.xlsx.load(buffer);
const worksheet = wb.worksheets[0];
const res = [];
worksheet.eachRow((row)=>{
const cs = [];
row.eachCell({ includeEmpty: true },(cell)=>{
var value = cell.value;
if(value!= undefined && typeof value == "object" && !(value instanceof Date)){
value = value.text
}
cs.push(value)
})
res.push(cs)
})
console.log(res)
return res;
}
export {
exportTableData
exportTableData,
downloadTemplate,
excelToJson
}