Google Sheet Api V4:无法在Google Sheet中获取单元格注释

时间:2020-07-23 18:19:20

标签: c# .net google-sheets google-sheets-api

我正在使用Google Sheet API。我面临阅读单元格注释的问题。 如下图所示,我能够读取单元格值,例如“ Ajay Gangwar”,但无法读取单元格注释,即“高级软件工程师”。

enter image description here

以下代码可以正常工作以从Google表格中读取数据:

    private static void readGoogleSheetNote(SheetsService sheetsService)
    {
        string spreadsheetId = "1FvPaJVu5z_Vml8eIqPK7q2WOWosOH-llL4p3FItg6Zo";
        string range = "Sheet1";

        SpreadsheetsResource.ValuesResource.GetRequest.ValueRenderOptionEnum valueRenderOption = (SpreadsheetsResource.ValuesResource.GetRequest.ValueRenderOptionEnum)0;
        SpreadsheetsResource.ValuesResource.GetRequest.DateTimeRenderOptionEnum dateTimeRenderOption = (SpreadsheetsResource.ValuesResource.GetRequest.DateTimeRenderOptionEnum)0;

        SpreadsheetsResource.ValuesResource.GetRequest getRequest = sheetsService.Spreadsheets.Values.Get(spreadsheetId, range);
        getRequest.ValueRenderOption = valueRenderOption;
        getRequest.DateTimeRenderOption = dateTimeRenderOption;

        Google.Apis.Sheets.v4.Data.ValueRange response = getRequest.Execute();
        Console.WriteLine(JsonConvert.SerializeObject(response));

        Console.ReadKey();
    }

以上代码的输出为:

enter image description here

1 个答案:

答案 0 :(得分:0)

您必须使用Method: spreadsheets.get来获取单元格注释,如从该资源的Cells概述中所见。

使用以下脚本,您将从A4单元格中获取数据。响应内有备注字段:

String spreadsheetId = "SPREADSHEET ID";
String range = "Sheet1!A4";
bool includeGridData = true;
SpreadsheetsResource.GetRequest request = service.Spreadsheets.Get(spreadsheetId);
request.Ranges = range;
request.IncludeGridData = includeGridData;
Data.Spreadsheet response = request.Execute();
Console.WriteLine(JsonConvert.SerializeObject(response.Sheets));