每当单元格值超过字符限制时记录到控制台

Logging to console whenever a cell value exceeds character limit

只要 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}`);
  }
}

此代码应该有效。它假定数据位于 Excel table / 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

}