Update a Cell with C# and Sheets API v4

前端 未结 6 894
甜味超标
甜味超标 2020-12-15 18:33

Does anyone have a good C# example for updating a cell with the v4 API?

I have the get cell values c# example from the developer website working with Google Sheets A

6条回答
  •  萌比男神i
    2020-12-15 19:00

    For anyone else that finds this thread. I got the exception below:

    Exception Details: Google.GoogleApiException: Google.Apis.Requests.RequestError 'valueInputOption' is required but not specified [400] Errors [ Message['valueInputOption' is required but not specified] Location[ - ] Reason[badRequest] Domain[global]]

    Solved with:

    SpreadsheetsResource.ValuesResource.UpdateRequest update = service.Spreadsheets.Values.Update(valueRange, spreadsheetId2, range2);
    update.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.RAW;
    UpdateValuesResponse result2 = update.Execute();
    

    Source:

    https://stackoverflow.com/a/38841369/3850405

    However this caused my data to get a single quote (') before the value I entered, like this:

    After reading the documentation I saw that the examples used "valueInputOption": "USER_ENTERED":

    https://developers.google.com/sheets/api/samples/writing#write_to_multiple_ranges

    After switching to ValueInputOptionEnum.USERENTERED everything worked as expected.

    updateRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
    

提交回复
热议问题