导出代码是
let list = res.data.data;
//下载全部数据
let datas = res.data.data.map((item) => {
return item.info;
});
console.log(datas);
for (let i = 0; i < datas.length; i++) {
var temp = new GC.Spread.Sheets.Workbook();
temp.fromJSON(JSON.parse(datas)); // 重命名样式表
temp.getNamedStyles().forEach(function (namedStyle) {
console.log(temp);
for (let i = 0; i < list.length; i++) {
let sheet = temp.getActiveSheet(i);
let patternCloseList = list.pattern_close; //获取需要插入的输入坐标
let rowColList = [];
//获取坐标值转换行列数值
patternCloseList.forEach((coordinate) => {
rowColList.push(
GC.Spread.Sheets.CalcEngine.formulaToRanges(
sheet,
coordinate
)[0].ranges[0]
);
});
// 行列数据打印清除相应数据
rowColList.forEach((rowCol) => {
sheet.getCell(rowCol.row, rowCol.col).foreColor("#E6A23C");
});
// 附表单元格文字颜色判断
let scheduleList = [];
list.template_bind_show.forEach((coordinate) => {
scheduleList.push(
GC.Spread.Sheets.CalcEngine.formulaToRanges(
sheet,
coordinate
)[0].ranges[0]
);
});
// 显示单元格附表文字颜色
scheduleList.forEach((rowCol) => {
sheet.getCell(rowCol.row, rowCol.col).foreColor("#66b1ff");
});
//获取坐标值给单元格赋值
let statementBlock = list.pattern;
statementBlock.forEach((block) => {
if (block.val != "") {
sheet.setValue(block.c, block.r, block.val); //获取坐标给单元格赋值
}
});
let looList = list.loop;
looList.forEach((loop) => {
for (let i = 0; i < loop.tr.total; i++) {
let currentLine = i + loop.tr.endLine;
sheet.addRows(currentLine, 1);
sheet.copyTo(
currentLine - 1,
0,
currentLine,
0,
1,
sheet.getColumnCount(),
2047
);
sheet.copyTo(
currentLine - 1,
0,
currentLine,
0,
1,
sheet.getColumnCount(),
32
);
var rh = sheet.getRowHeight(
currentLine - 1,
GC.Spread.Sheets.SheetArea.viewport
);
// 挂起事件响应
sheet.suspendEvent();
sheet.setRowHeight(
currentLine,
rh,
GC.Spread.Sheets.SheetArea.viewport
);
// 恢复事件响应
sheet.resumeEvent();
}
loop.trData.forEach((child, idx) => {
let lineLength = idx + loop.tr.startLine;
//数据长度小于等于结束直接赋值
child.forEach((childLoop) => {
if (typeof childLoop.val == "number") {
childLoop.val = childLoop.val.toString();
}
sheet.setValue(
lineLength - 1,
Number(childLoop.column),
childLoop.val
);
});
});
});
}
namedStyle.name = "sc" + i + "_" + namedStyle.name;
spread2.addNamedStyle(namedStyle);
});
var sheetCount = temp.getSheetCount();
for (let j = 0; j < sheetCount; j++) {
let sheet = temp.getSheet(j);
let sheetJSON = JSON.stringify(sheet.toJSON());
sheetJSON = sheetJSON.replace(
/"style":"/g,
'"style":"sc' + i + "_"
); // 如果存在parentName,则添加以下代码: // sheetJSON = sheetJSON.replace(/"parentName":"/g, '"parentName":"sc' + i + "_");
spread2.suspendPaint();
var newSheet = new GC.Spread.Sheets.Worksheet("sheet" + i + "_");
newSheet.fromJSON(JSON.parse(sheetJSON));
newSheet.name(newSheet.name() + i + "_" + j);
spread2.addSheet(spread2.getSheetCount(), newSheet);
spread2.resumePaint();
}
}
spread2.removeSheet(0);
let json = spread2.toJSON();
excelIO.save(
json,
function (blob) {
FaverSaver.saveAs(blob, "全部.xlsx");
},
function (e) {
console.log(e);
that.$message.error({
message: e.errorMessage,
duration: 1500,
});
}
);
} |