跳到主要内容

表格单元格设值不正确

问题描述

为表格单元格设置值时,设置结果不符合预期。

原因

表格存在合并单元格场景,可能使用了 information 获取列号,获取的是真实的(合并行列后的),而 cell.item 获取的是合并前的(被合并的单元格)。

解决:

需要在获取 cell.item 的时候进行循环,过滤掉为 undefineditem,采用以下方法获取 item,获取的结果是和 information 对应的:

getItem = async (row, index) => {
cellCount = await row.Cells.count;
console.log('cellCount', cellCount);
let num = 1;
for (let i = 1; i <= cellCount; i++) {
let currentCell = await row.Cells.item(i);
if (currentCell) {
if (num === index) {
return currentCell;
}
num += 1;
}
}
return null;
}