[英]Make Specific Part Bold in Google Sheets via Python gspread Api
I believe your goal is as follows.我相信你的目标如下。
bold specific part
in I would like to make bold specific part of my cell
.bold specific part
的文本I would like to make bold specific part of my cell
。 In this case, how about the following sample script?在这种情况下,下面的示例脚本怎么样?
spreadsheetId = "###" # Please set the Spreadsheet ID.
sheetName = "Sheet1" # Please set the sheet ID.
client = gspread.authorize(creds) # Please use your authorization script.
spreadsheet = client.open_by_key(spreadsheetId)
sheetId = spreadsheet.worksheet(sheetName).id
text = "I would like to make bold specific part of my cell"
gridRange = {"sheetId": sheetId, "startRowIndex": 0, "endRowIndex": 1, "startColumnIndex": 0, "endColumnIndex": 1}
reqs = [
{"updateCells": {
"range": gridRange,
"rows": [{"values": [{"userEnteredValue": {"stringValue": text}}]}],
"fields": "userEnteredValue"
}},
{"updateCells": {
"range": gridRange,
"rows": [{"values": [{"textFormatRuns": [
{"format": {"bold": True}, "startIndex": 21},
{"format": {"bold": False}, "startIndex": 39}
]}]}],
"fields": "textFormatRuns.format.bold"
}}
]
res = spreadsheet.batch_update({"requests": reqs})
I would like to make bold specific part of my cell
is put to a cell "A1" of "Sheet1", and the bold is set to the text of bold specific part
in the cell "A1" using the batchUpdate method.I would like to make bold specific part of my cell
的文本放入“Sheet1”的单元格“A1”,并将粗体设置为单元格“A1”中的bold specific part
的文本使用 batchUpdate 方法。 When this script is run, the following result is obtained.运行此脚本时,将获得以下结果。
If your cell "A1" has already had the text of I would like to make bold specific part of my cell
, you can also use the following request body.如果您的单元格“A1”中已经有文本
I would like to make bold specific part of my cell
,您也可以使用以下请求正文。
reqs = [ {"updateCells": { "range": gridRange, "rows": [{"values": [{"textFormatRuns": [ {"format": {"bold": True}, "startIndex": 21}, {"format": {"bold": False}, "startIndex": 39} ]}]}], "fields": "textFormatRuns.format.bold" }} ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.