第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 pygsheets 旋轉(zhuǎn) Google 表格中的文本?

如何使用 pygsheets 旋轉(zhuǎn) Google 表格中的文本?

qq_笑_17 2022-03-09 21:18:30
我正在嘗試使用 python 中的 pygsheets 在 Google Sheet 中旋轉(zhuǎn)一些長標(biāo)題名稱的文本。下面的代碼顯示了對 pygsheets 中提供的示例的輕微修改,根據(jù)文檔應(yīng)該可以工作。文本寫入正確的單元格,單元格 A1 為粗體,但單元格 B1 和 C1 未旋轉(zhuǎn)。沒有出現(xiàn)錯誤消息。知道為什么這不起作用嗎?import pygsheetssheet_url = "https://docs.google.com/spreadsheets/d/1t3nYyvkVkf6E36vTRucRQ35XQWbeRC--6U5h1chtikI"gc = pygsheets.authorize(service_file = "credentials.json")sh = gc.open_by_url(sheet_url)wks = sh.worksheet("title", "Sheet1")header = wks.cell('A1')header.value = 'Bold Text'header.set_text_format('bold', True)header.update()header2 = wks.cell('B1')header2.value = '45 Degree rotated text'header2.set_text_rotation('angle', 45)header2.update()header3 = wks.cell('C1')header3.value = 'Vertical Text'header3.set_text_rotation('vertical', True)header3.update()
查看完整描述

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é)果。

http://img1.sycdn.imooc.com//6228a9400001ad3306890270.jpg

筆記:

  • 這個修改后的腳本假設(shè) Sheets API 已經(jīng)可以使用。

  • 在將 pygsheets 更新為“pygsheets-2.0.1”后,我調(diào)查了上述修改。


查看完整回答
反對 回復(fù) 2022-03-09
  • 1 回答
  • 0 關(guān)注
  • 208 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號