How to add a new row?
Opened this issue · 5 comments
Hi,
Thanks for this awesome library. I am trying to programically manipulate a spreadsheet and your library seems a good fit. However when adding values to a Row that does not exist panics because the row is nil. It does work if I manually open the spreadsheet and paste something in it. This manual action is not practical since I intend to add a row every day across multiple worksheets.
i := 1
for {
if (something) {
break
}
ws.Rows[i][0].Update("foo") //Panics if the cell is not populated
i++
}
Hi,
Thanks for your comment. By default, this library fetch cells not empty because it's faster. You can try to get empty cells by setting ReturnEmpty
to true.
service.ReturnEmpty = true
If you get any other problems, feel free to ask me.
You now can use ExpandSheet
to expands the range of the sheet.
err := service.ExpandSheet(sheet, row, column)
Please reopen if you have more questions or issues.
@Iwark I am still unable to add a new cell.
I have tried using Expand Sheet and then calling synchronize, and yet it still fails on adding a new cell.
This works for me
service, _ := spreadsheet.NewService()
spreadsheet, _ := service.FetchSpreadsheet(SPREADSHEET_ID)
sheet, _ := spreadsheet.SheetByIndex(0)
service.ExpandSheet(sheet, 4, 4)
service.SyncSheet(sheet)
sheet.Update(3, 3, "foobar")
service.SyncSheet(sheet)