I'm trying to insert some rows to an Excel sheet which doesn't contain any tables, but I'm only able to insert blank rows. Attempting to change the values of these empty rows results in row.values printing the correct data, but the rows on the file itself are still blank, even after context.sync().
I have tried using the insert method from Excel.Range to insert an empty row successfully by doing:
let empty_space = sheet.getCell(index,0).getResizedRange(index, row.length)
empty_space.insert("Down")
I then tried using the reference to the new range empty_space to replace its values with those on an array called row (whose length was used to define the range above):
empty_space.load("values")
await context.sync()
empty_space.values[0] = row
If I then do console.log(empty_space.values), I see the correct values are listed, but the row in the file is still empty.
I also tried inserting the row into the sheet's used range via splice:
full_range.values.splice(index, 0, row)
Which does the same as above, printing correctly on the console but displaying empty cells.
How can I insert an array of values into a new row on top of the file, using Ranges. I can't convert the range to a table, as that creates a lot of other problems.
EDIT: Below is the full content of the function I'm using to try achieve this:
insert_banner = async ( sheet_range, context ) => {
let banner_rows = this.state.sheet_content.banner.banner_rows
for (let r in banner_rows) {
let index = parseInt(r)
let row = banner_rows[r]
let empty_space = this.state.sheet.getCell(index,0).getResizedRange(index, row.length)
empty_space.insert("Down")
empty_space.values[0] = row
await context.sync()
}
}
banner_rows is a 2-dimensional array.
EDIT 2: I tried using the set method of Excel.Range like this:
empty_space.set( {values: row} )
But regardless of what I try, I keep getting the following error:
"InvalidArgument: The number of rows or columns in the input array doesn't match the size or dimensions of the range."
Even though while debugging I can see that both row and empty_space.values do have the same dimensions, 1x48.
EDIT 3: Here's another approach I tried:
insert_banner = async ( sheet_range, context ) => {
let banner_rows = this.state.sheet_content.banner.banner_rows
let sheet_values = sheet_range.values
for (let r in banner_rows) {
let index = parseInt(r)
let row = banner_rows[r]
sheet_values.splice(index, 0, row)
}
return context.sync()
}
In this case, if I add a breakpoint after this function, I can see that sheet_ranges values do contain the correct information on the corresponding rows. I don't understand why this isn't being reflected in the file itself.