- Вы хотите использовать "textRotation" Sheets API с pyghseets.
Если мое понимание верно, как насчет этого ответа?В моем окружении я также могу подтвердить, что такая же проблема с вами произошла.Поэтому, когда я увидел скрипт "pygsheets", я заметил, что точка модификации скрипта.
Хотя параметры для textRotation
установлены, к сожалению, textRotation
не входит в тело запроса.Таким образом, textRotation
не работает.
Модифицированный скрипт:
Когда вы используете эту модификацию, пожалуйста, измените get_json()
из cell.py
в каталоге установленных "pygsheets"следующее.Я думаю, что может быть более простая модификация.Поэтому, пожалуйста, подумайте об этом, как об одном из нескольких ответов.
def get_json(self):
"""Returns the cell as a dictionary structured like the Google Sheets API v4."""
try:
nformat, pattern = self.format
except TypeError:
nformat, pattern = self.format, ""
if self._formula != '':
value = self._formula
value_key = 'formulaValue'
elif is_number(self._value):
value = self._value
value_key = 'numberValue'
elif type(self._value) is bool:
value = self._value
value_key = 'boolValue'
elif type(self._value) is str or type(self._value) is unicode:
value = self._value
value_key = 'stringValue'
else: # @TODO errorValue key not handled
value = self._value
value_key = 'errorValue'
ret_json = dict()
ret_json["userEnteredFormat"] = dict()
if self.format[0] is not None:
ret_json["userEnteredFormat"]["numberFormat"] = {"type": getattr(nformat, 'value', nformat),
"pattern": pattern}
if self._color[0] is not None:
ret_json["userEnteredFormat"]["backgroundColor"] = {"red": self._color[0], "green": self._color[1],
"blue": self._color[2], "alpha": self._color[3]}
if self.text_format is not None:
ret_json["userEnteredFormat"]["textFormat"] = self.text_format
fg = ret_json["userEnteredFormat"]["textFormat"].get('foregroundColor', None)
if fg:
ret_json["userEnteredFormat"]["textFormat"]['foregroundColor'] = {"red": fg[0], "green": fg[1],
"blue": fg[2], "alpha": fg[3]}
if self.borders is not None:
ret_json["userEnteredFormat"]["borders"] = self.borders
if self._horizontal_alignment is not None:
ret_json["userEnteredFormat"]["horizontalAlignment"] = self._horizontal_alignment.value
if self._vertical_alignment is not None:
ret_json["userEnteredFormat"]["verticalAlignment"] = self._vertical_alignment.value
if self._wrap_strategy is not None:
ret_json["userEnteredFormat"]["wrapStrategy"] = self._wrap_strategy
### Added -- begin
if self.text_rotation is not None:
ret_json["userEnteredFormat"]["textRotation"] = self.text_rotation
### Added -- end
if self._note is not None:
ret_json["note"] = self._note
ret_json["userEnteredValue"] = {value_key: value}
return ret_json
Результат:
Когда отразится вышеуказанная модификация, ваш скрипт получит следующий результат.
![enter image description here](https://i.stack.imgur.com/crRva.png)
Примечание:
- Этот измененный сценарий предполагает, что Sheets API уже можно использовать.
- Я исследовал выше модификацию послеЯ обновил pygsheets до "pygsheets-2.0.1".
Ссылки:
В моей среде я могу подтвердить, что с помощью "textRotation" работает вышеуказанная модификация.Но если это не сработало в вашей среде, я прошу прощения.