【问题标题】:Is it possible to get the range for a certain cell using spreadsheets api?是否可以使用电子表格 api 获取某个单元格的范围?
【发布时间】:2020-08-29 05:04:20
【问题描述】:

我目前正在编写一个 python 脚本来附加到一个谷歌表。 表单示例如下:

TSLA AAPL GOOGL
1    2    3
2    4    9
3    8    27

我想将值 4、5、6 附加到 TSLA,使其变为

TSLA AAPL GOOGL
1    2    3
2    4    9
3    8    27
4
5
6

为此,我目前正在尝试使用:

preadsheets().values().append(spreadsheetId=id, 
                              range=range_, 
                              valueInputOption='RAW', 
                              insertDataOption='INSERT ROWS', 
                              body=[1,2,3])

但是,我对应该如何处理 RANGE 感到困惑,因为我不能只输入 A 来表示第一列,因为有一天我也会有超过 26 列代表其他股票代码。 是否有可以返回范围的 sheet api 命令?

即:

#hypothetical command
spreadsheet().getColumnRangeofcell('TSLA') 

返回 A?

提前致谢!

【问题讨论】:

    标签: python excel api google-sheets google-sheets-api


    【解决方案1】:

    您可以像这样获取标题的名称:

    headers = wks.get_row(1, include_tailing_empty=False)
    

    然后可以在headers中找到元素TSLA的索引:

    pos = headers.index("TSLA") + 1
    

    如果pos=1,则TSLAA 列中。

    您可以选择获取带有标题TSLA 的列数据:

    TSLA_column = wks.get_col(pos,include_tailing_empty=False)
    

    然后你可以得到这个列的长度:

    size = len(first_column)
    

    【讨论】:

      猜你喜欢
      • 2018-01-29
      • 2012-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多