1

I am trying to append a row of cells in a spreadsheet using c# and the google sheets api. I got the code

    AppendCellsRequest appReq = new AppendCellsRequest();
    appReq.SheetId = 1;

The problem is that the only sheetID I got is from the url and is a String. Where do I find the sheet ID as an integer and how do I execute the AppendCellsRequest?

Hopes you can help.

2 Answers2

1

You may check this documentation and this example. The fields of CellData should be updated. At least one field must be specified. The root is the CellData; 'row.values.' should not be specified. A single * can be used as short-hand for listing every field.

// Create 'append cells' request for the current sheet.
   AppendCellsRequest appendRequest = new AppendCellsRequest();
   appendRequest.SheetId = 0;
   appendRequest.Rows = new[] { newRow };
   appendRequest.Fields = "*";

Here are some references which might help:

You may also check this link for the sample code.

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59
  • Can you please explain what is this "Fields" actually used for, What other values besides `*` can be given for this? – rahulkesharwani Nov 09 '19 at 14:42
  • 1
    Sorry for the noise, got answers to my doubt. Just in case if anybody else has a hard time figuring out: Fields are supposed to update thing from the set of values.eg: `fields: 'userEnteredValue,userEnteredFormat.textFormat.bold'` – rahulkesharwani Nov 09 '19 at 17:34
1

I suspect you're confusing "spreadsheetId" and "sheetId". The spreadsheet ID is the ID of the entire spreadsheet -- it's in the URL and is a long alphanumeric string (sometimes with dashes, underscores or some other characters). The "sheet ID" is the ID of a specific tab within the spreadsheet and is numeric.

Sheet IDs are visible in the URL after the "gid=" parameter, and are also available in the API from the spreadsheets.get call, under sheets.properties.sheetId.

Sam Berlin
  • 3,603
  • 12
  • 23