1 回答

TA貢獻1815條經(jīng)驗 獲得超10個贊
您想將 Sheets API 的“textRotation”與 pyghseets 一起使用。
如果我的理解是正確的,這個答案怎么樣?在我的環(huán)境中,我也可以確認(rèn)與您發(fā)生了同樣的問題。所以當(dāng)我看到“pygsheets”的腳本時,我注意到了腳本的修改點。
雖然textRotation設(shè)置了參數(shù),但不幸的textRotation是,請求正文中不包含。這樣,textRotation行不通。
修改后的腳本:
使用此修改時,請get_json()在cell.py已安裝的“pygsheets”目錄中修改如下。我認(rèn)為可能會有更簡單的修改。因此,請將此視為幾個答案之一。
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
結(jié)果:
反映上述修改時,您的腳本將獲得以下結(jié)果。
筆記:
這個修改后的腳本假設(shè) Sheets API 已經(jīng)可以使用。
在將 pygsheets 更新為“pygsheets-2.0.1”后,我調(diào)查了上述修改。
添加回答
舉報