wps表格单元格绘制卡顿

通过js加载项 API提供的表格操作接口,给200个单元格依次 进行赋值,设置样式(背景色,文本颜色,边框),公式,表格渲染有明细卡顿问题,有优化方案吗?

function renderJson(data) {

let currSheet = window.Application.ActiveSheet,

cells = currSheet.Cells,

dataCell,

cell,

row,

col;

// 行高

data.rows.forEach((row, index) => {

currSheet.Rows.Item(index + 1).RowHeight = row.size;

});

// 列宽

data.columns.forEach((column, index) => {

currSheet.Columns.Item(index + 1).ColumnWidth = column.size / 8;

});

data.rowCount = 20;

for (let i = 0; i < data.rowCount; i++) {

for (let j = 0; j < data.columnCount; j++) {

row = i + 1;

col = j + 1;

dataCell = data.data.dataTable[i][j];

cell = cells.Item(row, col);

cell.Value2 = dataCell.value;

dataCell.style.backColor && setBackColor(cell, dataCell.style.backColor);

dataCell.style.borderTop && setBorderTop(cell, dataCell.style.borderTop);

dataCell.style.borderRight && setBorderRight(cell, dataCell.style.borderRight);

dataCell.style.borderBottom && setBorderBottom(cell, dataCell.style.borderBottom);

dataCell.style.borderLeft && setBorderLeft(cell, dataCell.style.borderLeft);

}

}

}

function setBackColor(cell, color) {

cell.Interior.Color = Color.toInt(color);

}

function setBorderTop(cell, line) {

cell.Borders.Item(window.wps.Enum.xlEdgeTop).Color = line.color ? Color.toInt(line.color) : 0;

}

function setBorderRight(cell, line) {

cell.Borders.Item(window.wps.Enum.xlEdgeRight).Color = line.color ? Color.toInt(line.color) : 0;

}

function setBorderBottom(cell, line) {

cell.Borders.Item(window.wps.Enum.xlEdgeBottom).Color = line.color ? Color.toInt(line.color) : 0;

}

function setBorderLeft(cell, line) {

cell.Borders.Item(window.wps.Enum.xlEdgeLeft).Color = line.color ? Color.toInt(line.color) : 0;

}

河南省
浏览 378
收藏
1
分享
1 +1
6
+1
全部评论 6
 
陈俊东

@金山办公

当对单元格数据进行批量修改时,可以试一下暂时关闭自动计算和屏幕刷新,加快代码运行速度
· 广东省
回复
1000个单元格渲染还是至少3.5秒的耗时
· 河南省
回复