We made the bellow script to handle some company sheets and it worked fine for 2 months , before 3 weeks I saw it was throwing error.
last Loop ( aRowIndexes.forEach) , executes once for table1, adds the row, throws the error and stops.
error message : Table addRow: The argument is invalid or missing or has an incorrect format.
function main(workbook: ExcelScript.Workbook ){
// Get the table by its name.const table = workbook.getTable("TableMaster");const aTargetTables = [// workbook.getTable("TableTest")workbook.getTable("Table1"),workbook.getTable("Table2")workbook.getTable("Table3"),workbook.getTable("Table4"),workbook.getTable("Table5"),workbook.getTable("Table6"),workbook.getTable("Table7"),workbook.getTable("Table8"),workbook.getTable("Table9"),workbook.getTable("Table10"),workbook.getTable("Table11"),workbook.getTable("Table12")]const sourceRange = table.getRangeBetweenHeaderAndTotal();const dataRows: (number | string | boolean)[][] = table.getRangeBetweenHeaderAndTotal().getValues();
let projectWBSes = aTargetTables[0].getColumn(1).getRangeBetweenHeaderAndTotal().getValues().map(x => x[0]);
let newProjectWBSes = table.getColumn(1).getRangeBetweenHeaderAndTotal().getValues().map(x => x[0]);
let aRowIndexes: (number)[] = [];let aColumnIndexes: (number)[] = [];
newProjectWBSes.forEach((x, i) => {if(projectWBSes.indexOf(x)===-1){console.log("bike",x, projectWBSes.indexOf(x))aRowIndexes.push(i)}})if (aRowIndexes.length>0){aTargetTables.forEach( y => {aRowIndexes.forEach( x => {
dataRows[x][1] = '=IF(ISBLANK(VLOOKUP([@Project],TableMaster,2,FALSE))," ",VLOOKUP([@Project],TableMaster,2,FALSE))'dataRows[x][2] = '=IF(ISBLANK(VLOOKUP([@Project],TableMaster,3,FALSE))," ",VLOOKUP([@Project],TableMaster,3,FALSE))'dataRows[x][3] = '=IF(ISBLANK(VLOOKUP([@Project],TableMaster,4,FALSE))," ",VLOOKUP([@Project],TableMaster,4,FALSE))'dataRows[x][4] = '=IF(ISBLANK(VLOOKUP([@Project],TableMaster,5,FALSE))," ",VLOOKUP([@Project],TableMaster,5,FALSE))'dataRows[x][5] = "=SUM([@[Avlastimidou, Maria]:[add members at the Master sheet and save]])"console.log("x", x)console.log("datarows", dataRows)console.log("datarow", dataRows[x])
y.addRow(x, dataRows[x]); <==== Error is here})})
console.log("dataEntered" )
}console.log("finished" )}
x is an integer
dataRows[x] is an array of strings https://prnt.sc/G0kUgBv-Cciv https://prnt.sc/G0kUgBv-CcivnumberColums for each table (TableMaster and Table1,2,3 etc) are the same ( 44 )
addRow( ) documentation ExcelScript.Table interface - Office Scripts | Microsoft Learn
May you please help us ? :)