I have been trying to make a bold part of my cell using Gspread API. But I couldn't figure out how to do that. I found a way in that question but I couldn't integrate to Gspread API
I believe your goal is as follows.
bold specific part
in 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.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.
reqs = [
{"updateCells": {
"range": gridRange,
"rows": [{"values": [{"textFormatRuns": [
{"format": {"bold": True}, "startIndex": 21},
{"format": {"bold": False}, "startIndex": 39}
]}]}],
"fields": "textFormatRuns.format.bold"
}}
]