查找使用 C# 在 Sheets API 中创建的 google.sheet 文件

问题描述

我正在使用 Google.Apis.Sheets.v4

在创建凭据和初始化服务后,我使用以下内容创建了电子表格:

service.Spreadsheets.Create(Mynewsheet).Execute();

然后,使用 SpreadsheetsID 对新创建的电子表格进行更新或批量更新,例如:

SpreadsheetsResource.ValuesResource.UpdateRequest request = service.Spreadsheets.Values.Update(requestBody,awsomNewSheet.SpreadsheetId,range);

成功并收到回复,但我在 Google 云端硬盘中找不到新创建的文件

有指导吗?

解决方法

它应该已在您的 Google 云端硬盘中创建并可用。

但作为一种解决方法,当您使用 Spreadsheet.create() 时,它会返回一个 Spreadsheet Resource 响应正文。

我有 3 个选择:

  1. properties->title 下的响应正文中获取 file's title 并使用以下搜索查询在您的 Google Drive 中搜索具有特定标题的文件:

    title:<replace with your file title>

  2. 从响应正文中获取 spreadsheetUrl 并使用它来访问您的文件

  3. 从响应正文中获取 spreadsheetId 并使用它通过以下链接访问您的文件:

    https://docs.google.com/spreadsheets/d/<replace with spreadsheet id>/edit?


使用 API Explorer 的示例响应正文:

{
  "spreadsheetId": "1TNK_uduyRQ82TQQJ13qtLnu58bDZxxxxxx","properties": {
    "title": "Sheet API Test","locale": "en_US","autoRecalc": "ON_CHANGE","timeZone": "Etc/GMT",},.....
    
  "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/1TNK_uduyRQ82TQQJ13qtLnu58bDZxxxxxx/edit?ouid=xxxxxx&urlBuilderDomain=example.com"
}