1

ItemNumber每当列中单元格值的长度超过 10 个字符时,我都会记住这个伪代码来记录错误。我还想显示有问题的行号。

还没有机会对此进行全面测试,但有可能吗?

任何帮助将非常感激!

let itemDesc = newTable.getColumnByName("ItemNumber")
for (let i = itemDesc.length - 1; i >= 0; i--) {
  let event = itemDesc[i];
  let rowNumber = ???
  if (event.length > 10) {
    console.log(`Character count exceeds 10 characters at Rows: ${rowNumber}`);
  }
}
4

1 回答 1

2

这段代码应该可以工作。它假定数据在 Excel 表/ListObject 中:

function main(workbook: ExcelScript.Workbook) {
let ws = workbook.getActiveWorksheet();
let newTable = ws.getTable("Table1");
let itemDesc = newTable.getColumnByName("ItemNumber");
let rang = itemDesc.getRange();
let vals = rang.getValues();
let rowNumbers = []
vals.forEach((item, rowNumber) => {
    if (rowNumber > 0 && item[0].toString().length > 10) {
        rowNumbers.push(rowNumber)
    }
})
rowNumbers.forEach(row => console.log(`Character count exceeds 10 characters at Rows: ${row}`)) //prints each offending row on a separate line
console.log(`Character count exceeds 10 characters at Rows: ${rowNumbers.toString()}`); //prints all offending rows on one line

}

于 2021-07-18T18:12:45.043 回答