通过以下内容,我可以以编程方式在 Google 表格中创建电子表格,但该表格的所有者是开发者帐户(一个以“gserviceaccount.com”结尾的疯狂字符串),而我的普通帐户无法查看该电子表格。我还需要做什么才能将 Google 用户添加到读/写权限?
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient import discovery
# ... json_key is the json blob that has the credentials
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_dict(json_key, scope)
service = discovery.build('sheets', 'v4', credentials=credentials)
spreadsheet = {
  "properties": {"title": "my test spreadsheet"}
}
service.spreadsheets().create(body=spreadsheet).execute()
编辑:
我尝试将范围更改为,['https://www.googleapis.com/auth/drive']但下面的答案仍然对我不起作用。当我跑步时  
print [xx for xx in dir(service) if not xx.startswith('_')]
我明白了
['new_batch_http_request', u'spreadsheets']
换句话说,这不是我定义的服务permissions()中的方法。service我应该采取什么不同的做法?
我已成功将 Big Query 与 Google Sheets 集成。
由于我使用动态参数来决定查询的性质(例如时间范围),因此我想了解查询的“成本” - 运行需要多少 MB(或 KB 或 GB)。
在运行查询之前有什么办法可以得到这样的指示吗?
我有一个脚本,它从电子表格中获取行,并为每一行创建单独的电子表格文件。然后脚本将它们发布到网络上。
我无法获得的是 id,它允许我获得它的网络版本的 url。
常规电子表格 ID 如下所示:
1N8h00iN2L7aaUbI9TYRWioaZHjHNSc_vNucCbVADj1o
发布到网络的 id 如下所示:
2PACX-1vTPSkv4Rz7CqwabTTfxa3xcVF-Gzxu7IboLyLkfoShP2d3qdX8o0qdvk5d_nWZD2rq43E2LXmVAm5HI
(更长,以2PACX-开头)
有人知道怎么做吗?
提前致谢。
我正在使用 Google Sheets v4 API,并且想使用 Google Sheets UI 上提供的橙色 FF9900,但 API 中的 RGBA 不遵循标准颜色 RGBA。从这个工具中,我得到橙色的 rgba(236, 161, 51, 1)。
这是我使用 Google API Explorer 的请求代码:
{
        requests: [{  
          repeatCell: {
            range:{
              sheetId: correctsheetid,
              startRowIndex: 2,
              endRowIndex: 3,
            },
            cell:{
              userEnteredFormat:{
                backgroundColor: {
                  red: 236, 
                  green: 161, 
                  blue: 51
                }
              }
            },
            fields: 'userEnteredFormat(backgroundColor)'
          }
        }]
      }
但是,工作表上的输出是蓝色的,而不是预期的橙色。
我已经看过人们遇到类似问题的帖子,但找不到明确的答案。
我尝试使用以下代码行检索 264735 个插槽的二维数组:
  var optionalArguments = {majorDimension: "ROWS",
                     valueRenderOption: "FORMULA",
  };
  var sourceValuesObject = Sheets.Spreadsheets.Values.get(spreadsheetId, rangeA1Notation, optionalArguments)
但这是我得到的:
响应代码:413。消息:响应太大。
这看起来很奇怪,因为我看不到这种限制写在任何地方,加上如果 300000 个或更少的单元格导致 API 错误,用户如何获取大量数据。
我尝试过拆分请求并且它有效,但这使我的代码变得更加复杂且速度更慢,而且在尝试将值更新回工作表范围时我得到空响应。
我指向正确的方向吗?这是正常的吗?有解决方法吗?
编辑: 这是一个示例电子表格
首先,我尝试使用循环Sheets.Spreadsheets.Values.get
内部来获取分割范围for,并且它有效。
做同样的事情batchGet会给我同样的错误,所以我想单元格内的数据太大了。
javascript google-apps-script http-status-code-413 google-sheets-api
众所周知,为了从 Google Sheets API 中的行列中获取值,格式如下:
gapi.client.sheets.spreadsheets.values.get({
  spreadsheetId: id,
  range: "myData!A1:E" 
}).then(res => {
  console.log(res.result);
}, err => console.log(err));
请注意,“范围”必须在特定参数内,但如何简单地获取最大范围内的值?是否有像“myData!Min:Max”这样的简写?我知道您可以提出另一个请求来获取最大行和列长度:
sheets.spreadsheets.get({
    spreadsheetId: id,
    ranges: [],
    auth: something
}, (err, resp) => {
    var sheetOne = resp.data.sheets[0];
    console.log(sheetOne.properties.gridProperties); // { rowCount: 1024, columnCount: 7 } (for example)
})
然后一旦我有了,理论上我可以使用数字到字母的切换系统自动生成范围字符串以获取列字母名称或类似的内容,并发出另一个请求以获取最大列,但首先:
有什么办法可以用 API 来做到这一点吗?
google-sheets node.js google-api-nodejs-client google-sheets-api
我想使用 PyGSheets 在我的 Google Drive 文件夹中创建电子表格。我还希望能够设置使用代码创建工作表的目录/文件夹。具体来说,我想输入一个类似于 URL 的字符串,甚至只是文件夹的名称。
我已经查看了 PyGSheets 文档和“电子表格”模型。我还没有找到任何接受文件夹名称或目录地址的类。也没有用于将工作表从一个文件夹移动到另一个文件夹的类。使用 PyGSheets 可以进行任一操作吗?
shtTargetedCreate = con.create("Test Folder",folder="1GwA4W8iv-26BvG48nKnEigYqDL8SpUGK")
有没有更有效的方法来做到这一点?
我的代码如下
def write_cells(spreadsheet_id, update_data):
updating = sheet_service.spreadsheets().values().\
        batchUpdate(spreadsheetId=spreadsheet_id, body=update_data)
updating.execute()
spreadsheet_data = [
    { 
        "deleteDimension": {
        "range": {
          "sheetId": sheet_id,
          "dimension": "ROWS",
          "startIndex": 5,
          "endIndex": 100
         }              
        }
       }
]    
update_spreadsheet_data = {
    'valueInputOption': 'USER_ENTERED',
    'data': spreadsheet_data
}
update_data = update_spreadsheet_data
write_cells(spreadsheet_id, update_data)
我有以下错误消息
HttpError                                 Traceback (most recent call last)
<ipython-input-64-0ba8756b8e85> in <module>()
----> 1 write_cells(spreadsheet_id, update_data)
2帧
/usr/local/lib/python3.6/dist-packages/googleapiclient/http.py in execute(self, http, num_retries)
    838       callback(resp)
    839     if resp.status >= 300:
--> 840       raise HttpError(resp, content, uri=self.uri)
    841     return self.postproc(resp, …google-sheets python-3.x google-sheets-api google-colaboratory
我只是在以下位置测试 Google Sheets API:
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append
我正在使用该Try this API部分填写请求参数并执行请求(向工作表追加一行)。
我遵循了Step 1这里:
https://developers.google.com/sheets/api/quickstart/js
为了:
因此,我有:
在Try this API>Credentials部分,有两个复选框:
我尝试uncheck了Google OAuth 2.0选项,这样我可以使用刚刚发出请求API Key-但我看不到,我可以进入的API Key。
如何在Try this API部分中定义 API 密钥,以便我可以仅使用API Key(而不是Google OAuth 2.0 )发出请求。
我一步一步地关注了 TechWithTim 的视频 ( https://www.youtube.com/watch?v=cnPlKLEGR7E ),但是当我尝试打开工作表时仍然出现错误。代码工作正常,直到sheet = client.open("GuildTaxes").sheet1行。这是我的代码。
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ["https://spreadsheets.google.com/feeds","https://www.googleapis.com/auth/sprea...",
        "https://www.googleapis.com/auth/drive...","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("GuildTaxes-9ba4508be840.json", scope)
client = gspread.authorize(creds)
sheet = client.open("GuildTaxes").sheet1
data = sheet.get_all_records()
print(data)