Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a new row? #10

Open
sajal opened this issue Jun 30, 2016 · 5 comments
Open

How to add a new row? #10

sajal opened this issue Jun 30, 2016 · 5 comments

Comments

@sajal
Copy link

sajal commented Jun 30, 2016

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++
}
@Iwark
Copy link
Owner

Iwark commented Jul 1, 2016

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.

@Iwark
Copy link
Owner

Iwark commented Nov 12, 2016

You now can use ExpandSheet to expands the range of the sheet.

err := service.ExpandSheet(sheet, row, column)

@Iwark
Copy link
Owner

Iwark commented Nov 12, 2016

Please reopen if you have more questions or issues.

@Iwark Iwark closed this as completed Nov 12, 2016
@kilpatty
Copy link

kilpatty commented Jun 4, 2018

@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.

@Iwark Iwark reopened this Jul 10, 2018
@bunker-inspector
Copy link

bunker-inspector commented Sep 26, 2020

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants