Some code using office script to copy one row on an existing table (that only has one row in it!) to a new row on an existing table.
Anyway to the question? What is the right way to use office script to copy a row from one table to a new (last) row in another table?
The source table will only *ever* have one row in it, by design.
The target table will be an ever expanding table of rows.
VBA Code:
function main(workbook: ExcelScript.Workbook) {
let CurrentWorksheet = workbook.getWorksheet("Audit File History");
let SourceTable = workbook.getTable("SampleTable");
let TargetTable = workbook.getTable("PracticeTable");
let SourceRange = SourceTable.getRangeBetweenHeaderAndTotal();
let SourceData = SourceRange.getValues();
//if I don't include this line, I get a two dimensional array?!
let FlatData = SourceData[0];
//Actual data array.
let PasteArray: [] = [];
PasteArray.push(FlatData);
console.log(FlatData);
//Dummy fixed data array, to compare with actual data array in console.
let FixedData: string [] = [];
FixedData.push("one","two","three");
console.log(FixedData);
/*
Result: I get two identical looking outputs in console.log.
However the error I get in Excel is this:
"[13, 17] Argument of type '(string | number | boolean)[]' is not assignable to parameter of type 'never'."
Log output(s):
(10) ["0D395D2E58", "Nation", 123456, 123456, "", "My Record", "Also", "Ran", "Yes", 123456]
(3) ["one", "two", "three"]
*/
TargetTable.addRow(-1, FlatData);
//The above line just errors, although from what I've read I need to insert new data as type array, to use the addrow command?
}
Anyway to the question? What is the right way to use office script to copy a row from one table to a new (last) row in another table?
The source table will only *ever* have one row in it, by design.
The target table will be an ever expanding table of rows.