Is there a way to set RTL (Right-to-left) and LTR (left-to-right) to sheets/cells in Python, perhaps with gspread or gspread-formatting packages? Does Google Sheet's API even support this?
I couldn't find any related documentation...
UPDATE: I eventually did find right-to-left reference in Google Sheet's API for sheets and for text in cells. So this may be a matter of implementation in the python packages. I went ahead and opened a gspread package feature request and gspread-formatting package feature request
CodePudding user response:
I believe your goal is as follows.
- You want to change "RTL" and "LTR" of the sheet in Google Spreadsheet.
- You want to achieve this using gspread for python.
In your situation, how about the following sample script?
Sample script:
client = # Please use your client of gspread.
spreadsheetId = "###" # Please set your Spreadsheet ID.
sheetName = "Sheet1" # Please set your sheet name.
spreadsheet = client.open_by_key(spreadsheetId)
sheet = spreadsheet.worksheet(sheetName)
data = {
"requests": [
{
"updateSheetProperties": {
"properties": {"rightToLeft": True, "sheetId": sheet.id},
"fields": "rightToLeft",
}
}
]
}
spreadsheet.batch_update(data)
- When this script is run, the sheet of
sheetName
of Spreadsheet ofspreadsheetId
is used.
References:
- batch_update(body)
- UpdateSheetPropertiesRequest
rightToLeft
: True if the sheet is an RTL sheet instead of an LTR sheet.