明树Git Lab

Commit 34260035 authored by zfp1's avatar zfp1

update

parent 6588ab91
Pipeline #104237 passed with stage
in 3 seconds
......@@ -8,6 +8,7 @@ const ExcelJS = require('exceljs');
const path = require('path');
const { HyperFormula } = require('hyperformula');
const errorMessage = require("../utils/errorMessage");
const _ = require('lodash');
const keyName = {
tjjh: "投决计划",
......@@ -33,16 +34,31 @@ async function getXmtzzjllTem({ startYear, endYear, tampName, projectId }) {
}
// 2.2 处理数据
let rows = Array(worksheet.actualRowCount - 3).fill(Array(columns.length).fill("")); // 5 是模板有5行
let rows = []; // 5 是模板有5行
if (projectId) {
let tzzjlls = await DB.ProjectTzzjll.findAll({
where: { projectId: projectId, del: 0 },
let excelData = await DB.ProjectExcelData.findOne({
order: [['createdAt', 'DESC']],
where: { projectId: projectId, del: 0, tampName },
attributes: ['data', 'createdAt', 'id'],
raw: true,
});
tzzjlls = _.sortBy(tzzjlls, 'year');
rows = thvc(tzzjlls);
console.log(excelData.id);
if (excelData && excelData.id && _.isArray(excelData.data) && excelData.data.length > 0) {
for (let index = 3; index < excelData.data.length; index++) { // 0、1行是表头
let element = excelData.data[index];
if (index) {
element = element.slice(3);
}
console.log(rows, "=============")
console.log(element)
rows.push(element);
}
} else {
rows = Array(worksheet.actualRowCount - 3).fill(Array(columns.length).fill(""))
}
} else {
rows = Array(worksheet.actualRowCount - 3).fill(Array(columns.length).fill(""))
}
// console.log(rows, "=============")
// 使用addTable创建表格
worksheet.addTable({
......@@ -170,7 +186,7 @@ async function importExcelTempData(req, res, next) {
} else if (cell.type === ExcelJS.ValueType.String) {
rowData.push(cell.text + "_suffix");
} else if (cell.value === null || cell.value === undefined) {
rowData.push(null);
rowData.push("");
} else {
rowData.push(cell.value);
}
......@@ -187,14 +203,15 @@ async function importExcelTempData(req, res, next) {
// const formulaString = hf.getCellFormula({ sheet: 0, row: r, col: c });
let calculated = hf.getCellValue({ sheet: 0, row: r, col: c });
// console.log(formulaString, calculated)
if(typeof calculated == 'string') {
calculated = removeSuffix(String(calculated),'_suffix')
if (typeof calculated == 'string') {
calculated = removeSuffix(String(calculated), '_suffix')
}
cc.push(calculated);
}
out.push(cc);
}
await DB.ProjectExcelData.create({projectId, tampName, data: out});
await DB.ProjectExcelData.create({ projectId, tampName, data: out });
req.file = null;
return res.sendData(out);
} catch (error) {
next(error)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment