【问题标题】:Changing cell to number using gspread python API使用 gspread python API 将单元格更改为数字
【发布时间】:2021-08-24 14:13:28
【问题描述】:

我正在将数据框写入电子表格,我加粗、更改字体等,但我无法将格式更改为数字格式:

from gspread_formatting import *
import gspread
from df2gspread import df2gspread as d2g
import pandas as pd

d2g.upload(data, sheet.id, 'test_name', clean=True, credentials=creds, col_names=True, row_names=False)
worksheet = sheet.worksheet('test_name') 
worksheet.format("1", {
    "backgroundColor": {
      "red": 1.0,
      "green": 1.0,
      "blue": 1.0
    },
    "horizontalAlignment": "CENTER",
    "textFormat": {
      "fontSize": 12,
      "bold": True
    }})

worksheet.format("D:R", {            # <--- this does not work
      "numberFormat": {
      "type": "NUMBER"}
    })

    set_row_height(worksheet, '1:100', 40)
    set_column_width(worksheet, 'A:R', 125)

我正在尝试关注this documentation。 我还检查了this answer

但格式仍然是自动的,而不是数字。

【问题讨论】:

    标签: python google-sheets gspread


    【解决方案1】:

    不是解决方案,我遇到了类似的问题,但我的解决方法是直接在 google 表格中创建一个宏,以便将格式应用于所需的表格。

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多