【问题标题】:Finding cell using Pygsheets and update cells in the same column使用 Pygsheets 查找单元格并更新同一列中的单元格
【发布时间】:2020-09-30 13:03:21
【问题描述】:

我需要每周用一些数字更新 Google 表格中的日历。 我正在使用 pygsheets find 来查找日期,但是我无法获取该单元格的列,因此我可以更新该列中的一些行。

enter code here
for key in list:
    sheet_name = list[key]
    print(sheet_name)
    # Access the sheet
    sheet = report.worksheet_by_title(sheet_name)
    header = sheet.find(first_day_period)
    print(header)
[<Cell H2 '21 Sep 2020'>]

find 返回的是一个单元格列表,但如果不拆分结果,然后使用它来查找单元格,我就无法访问该列。我想知道是否有更简单、更清洁的方法。

【问题讨论】:

    标签: python google-sheets pygsheets


    【解决方案1】:

    答案:

    可以通过Cell.col获取列值。

    更多信息和示例:

    根据 Cell 类的 pygsheets 文档,有一个 col 值:

    col

    单元格的列号。

    import pygsheets
    
    gc = pygsheets.authorize()
    ss = gc.open_by_key('sheet-id')
    sheet = ss.worksheet_by_title(sheet_name)
    header = sheet.find(first_day_period)
    
    print(header[0].col)
    

    假设first_day_period 中包含的值在单元格I1 中,控制台输出将为:

    9
    

    参考资料:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-28
      • 2014-02-03
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      相关资源
      最近更新 更多