根據關于
uj5u.com熱心網友回復:
不幸的是,雖然我不確定我是否能正確理解您的問題,但從您提供的問題中,我理解您的目標如下。
關于
As can be seen in the attached photo, the lines dont extend all the way to the column AE, but rather stop at Z (see red lines in photo). I tried to edit the code and make endColumnIndex higher than 26 but it doesnt help.,在這種情況下,您只想修改垂直線。不需要修改水平線。您想將該行放在“AE”列的右側。關于
How do I make the contents of the sheet to be center alligned? I already auto fit them as shown in code below.,您想為作業表的所有單元格設定此項。關于
Yes I need both horizontal and vertical lines which are missing (red lines). For center alignment: I would like that for the entire sheet.,當我看到你的影像時,紅線只是水平線。從您的影像中,您可能希望在“AA”和“AB”列之間放置垂直線。而且,您可能希望將“B”列左側的水平線放在“AE”列的右側。而且,您可能希望在整個作業表中反映中心對齊。
如果我對您的 2 個目標的理解是正確的,那么以下修改如何?
修改后的腳本:
在這種情況下,請修改以下行下方的顯示腳本### Autofit Columns and Rows width:。
### Autofit Columns and Rows width:
request_body = {
"requests": [
{
"autoResizeDimensions": {
"dimensions": {
"sheetId": sheet_id,
"dimension": "COLUMNS",
"startIndex": 0,
"endIndex": 31,
}
}
},
{
"autoResizeDimensions": {
"dimensions": {
"sheetId": sheet_id,
"dimension": "ROWS",
"startIndex": 0,
"endIndex": 1000,
}
}
},
]
}
##### Sketching horizontal rows after each Week:
temp = -1
n = []
for index, row in df_final.iloc[:, 7:8].iterrows():
s = "".join(row.astype(str).tolist())
if temp != s:
n.append(index)
temp = s
offset = 7
requests = [
{
"repeatCell": {
"cell": {
"userEnteredFormat": {"borders": {"top": {"style": "SOLID_THICK"}}}
},
"range": {
"sheetId": sheet_id,
"startRowIndex": e offset,
"endRowIndex": e 1 offset,
"startColumnIndex": 1,
"endColumnIndex": 31,
},
"fields": "userEnteredFormat.borders",
}
}
for e in n
]
##### Sketching vertical lines in between predefined columns:
end = len(v) offset - 1
add_requests1 = [
{
"repeatCell": {
"cell": {
"userEnteredFormat": {"borders": {"left": {"style": "SOLID_THICK"}}}
},
"range": {
"sheetId": sheet_id,
"startRowIndex": 6,
"endRowIndex": end,
"startColumnIndex": a,
"endColumnIndex": b,
},
"fields": "userEnteredFormat.borders.left",
}
}
for [a, b] in [
[1, 2],
[2, 3],
[6, 7],
[10, 11],
[15, 16],
[17, 18],
[21, 22],
[22, 23],
[23, 24],
[27, 28],
[31, 32],
]
]
add_requests2 = [
{
"repeatCell": {
"cell": {
"userEnteredFormat": {"borders": {"top": {"style": "SOLID_THICK"}}}
},
"range": {
"sheetId": sheet_id,
"startRowIndex": a,
"endRowIndex": b,
"startColumnIndex": 1,
"endColumnIndex": 31,
},
"fields": "userEnteredFormat.borders.top",
}
}
for [a, b] in [[6, 7], [end, end 1]]
]
add_requests3 = [
{
"updateSheetProperties": {
"properties": {
"gridProperties": {"frozenRowCount": offset},
"sheetId": sheet_id,
},
"fields": "gridProperties.frozenRowCount",
}
}
]
add_requests4 = [
{
"repeatCell": {
"cell": {"userEnteredFormat": {"horizontalAlignment": "CENTER"}},
"fields": "userEnteredFormat.horizontalAlignment",
"range": {"sheetId": sheet_id},
}
}
]
requests.extend(add_requests1)
requests.extend(add_requests2)
requests.extend(add_requests3)
requests.extend(add_requests4)
service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_id, body={"requests": requests}).execute()
- 我認為在你的目標中,
endColumnIndex應該是31。 - 為了設定單元格值的中心對齊,我添加了
add_requests4.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/481102.html
標籤:Python 熊猫 数据框 谷歌表格 谷歌表格 API
