Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python中的Google Sheets API v4更改列宽?_Python_Google Sheets Api - Fatal编程技术网

如何使用Python中的Google Sheets API v4更改列宽?

如何使用Python中的Google Sheets API v4更改列宽?,python,google-sheets-api,Python,Google Sheets Api,我正在尝试使用Google Sheets API更改列宽。我知道spreadsheetId我可以使用ss_drive.get('id')获取,但我不知道如何获取sheetId: ss_drive = drive_api.files().create(body=file_metadata).execute() ssId = ss_drive.get('id') sheets_api = build('sheets', 'v4', credentials=credentials) request

我正在尝试使用Google Sheets API更改
列宽。我知道
spreadsheetId
我可以使用
ss_drive.get('id')
获取,但我不知道如何获取
sheetId

ss_drive = drive_api.files().create(body=file_metadata).execute()
ssId = ss_drive.get('id')

sheets_api = build('sheets', 'v4', credentials=credentials)

requests = []
requests.append({
    "updateDimensionProperties": {
    "range": {
      "sheetId": sheetId,
      "dimension": "COLUMNS",
      "startIndex": 0,
      "endIndex": 1
    },
    "properties": {
      "pixelSize": 160
    },
    "fields": "pixelSize"
    }
})

response = sheets_api.spreadsheets().batchUpdate(
    spreadsheetId=ssId, body={'requests': requests}).execute()

我将
“sheetId”:sheetId
更改为
“sheetId”:0
。列的宽度也改变了。

您的帐户中可以存储多张工作表,因此您需要事先知道工作表ID。您可以登录到,导航到您选择的工作表,URL如下所示:

https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms

d/
后面的标记是电子表格的ID,您可以根据。

从示例中使用以下命令获得
1BXIMV0xRA5NFMDKVBDBZJGMUQPTLBS74OGVE2UPMS
:ss_drive.get('ID')
。它被称为
电子表格ID
。我的问题是如何获得
“sheetId”:sheetId
?它们不一样。@F.Vosnim这取决于您如何命名该表。如果您不知道其中的内容,可以使用
电子表格()获取概述。获取
。请看我链接的问题。我的意思是,您所说的都无助于更改列宽。我在代码中放置了
“sheetId”:0
,它成功地更改了列的宽度。这意味着
Sheet1、Sheet2、Sheet3…
具有
sheetId=0、1、2…
。考虑你的例子:代码> 1bimvs0xr5nfdbjbjdjguuqqbbss7gov2uppm < /Cord>是你的<代码>电子表格> /COD>,但是这个电子表格中的第一张表有<代码> SHITED=0 < /C> > .f.VoSnIM,只要你不删除这张表是真的。现在删除
Sheet1
,第一张图纸仍然有
sheetId==1
。因此,通常不能假设第一张图纸的id为
0
。如果您移动工作表,也同样适用。您是对的,我删除了第一张工作表,第二张工作表变成了
“sheetId”:876005509