使用ExcelJS将一系列单元格和/或整个工作表从一个Excel工作表复制到另一个工作表是否可能/是否有便利功能?
答案 0 :(得分:1)
var sourceWorkbook= new Excel.Workbook();
var sourceWorksheet;
sourceWorkbook.xlsx.readFile("template.xlsx").then(function(){
sourceWorksheet= sourceWorkbook.getWorksheet(1);
var targetWorkbook = new Excel.Workbook;
var targetSheet = targetWorkbook.addWorksheet();
sourceWorksheet.eachRow((row, rowNumber) => {
var newRow = targetSheet.getRow(rowNumber);
row.eachCell((cell, colNumber) => {
var newCell = newRow.getCell(colNumber)
for(var prop in cell)
{
newCell[prop] = cell[prop];
}
})
})
这就是我对项目所做的。效果很好。
答案 1 :(得分:0)
您可以使用ExcelJS将整个工作表从一个Excel工作表复制到另一个工作表。下面的代码可以工作
var tall = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
let sum = 0;
for (let i = 0; i < tall.length; i += 2){
sum += tall[i];
}
console.log(sum)
答案 2 :(得分:0)
复制带有合并单元格的工作表
var ws1 = workbook.getWorksheet('demo');
let copySheet = workbook.addWorksheet('newdemo');
copySheet.model = Object.assign(ws1.model, {
mergeCells: ws1.model.merges
});
copySheet.name = 'new demo';