轻松高效地管理google工作表

gsheet-api的Python项目详细描述


GSheet API

轻松高效地管理谷歌工作表。

安装

pip install gsheet-api

注释

  • 所需的凭据是google服务帐户json文件
  • 工作表必须与对找到服务帐户的client_email的编辑访问共享
  • 凭据可以作为字典或json文件的文件路径输入,两者都可以工作。

用法示例

**必需的参数在“可用方法”部分中定义

fromgsheet_apiimportGSheetAPIgsheet=GSheetAPI(**)# initialize the classgsheet.sheet_to_df(**)# import data from the sheet to a Pandas DataFramegsheet.change_gsheet(**)# switch to a new Google Sheet to work off ofgsheet.get_cell(**)# get the contents of a single cellgsheet.change_tab(**)# switch to a new tab in the current working Google Sheetgsheet.set_cell(**)# set the value of a single cellgsheet.df_to_sheet(**)# export a Pandas DataFrame to the current working sheetgsheet.timestamp_to_cell(**)# export a timestamp to a single cell in the sheet

可用方法

__init__(self, credentials, sheet_id, tab_name)
    Initializes the GSheetAPI and sets the current working sheet and current working tab
    :param dict|str credentials: Dictionary containing your Google Service Account json blob or a file
        path entered as a string
    :param str sheet_id: Sheet id found in the Google Sheet URL
    :param str tab_name: Name of the tab to use within the Google Sheet

change_gsheet(self, sheet_id, tab_name)
    Changes the current working sheet
    :param str sheet_id: Sheet id found in the Google Sheet URL
    :param str tab_name: Name of the tab to use within the Google Sheet

change_tab(self, tab_name)
    Changes the working tab name within the current sheet
    :param str tab_name: Name of the tab to use within the Google Sheet

df_to_sheet(self, df_input, row_start, col_start, clear_sheet=False, clear_range=None, allow_formulas=True, 
            include_index=False, resize=False, include_column_header=True)
    Exports a Pandas DataFrame to a Google Sheet
    :param pandas.DataFrame df_input: DataFrame to export
    :param int row_start: Integer value of the row (starting at 1)
    :param int col_start: Integer value of the column (starting at 1)
    :param bool clear_sheet: (default False) If the entire sheet should be cleared before dumping data
    :param bool clear_range: (default None) A range that should be cleared (eg. 'A1:B12')
    :param bool allow_formulas: (default True) Whether or not formulas should be executed or shown as a raw string
    :param bool include_index: (default False) Whether or not the DataFrame index should be shown in the sheet
    :param bool resize: (default False) If the sheet should resize when the data is too large to fit in the sheet
    :param bool include_column_header: (default True) If the data header should be dumped into the sheet

get_cell(self, cell)
    Gets the current value of a given cell in the sheet
    :param str cell: Cell reference (eg. 'A2')
    :return: The current contents of the cell

set_cell(self, cell, cell_content)
    Sets a cell to a given value
    :param str cell: Cell reference (eg. 'A2')
    :param str cell_content: Desired cell content

sheet_to_df(self, col_list, header, evaluate_formulas)
    Grabs data from a Google Sheet and returns it as a Pandas DataFrame
    :param list col_list: List of ints representing the column number to extract (eg. range(0, 4) for [0, 1, 2, 3])
    :param int header: Integer of the row to use as a column (0 indexed)
    :param bool evaluate_formulas: Whether or not the formulas should be computed before extracting the cell content
    :return pandas.DataFrame: The sheet contents as a DataFrame object

timestamp_to_cell(self, cell, fmt='%Y-%m-%d %H:%M %Z', tz='US/Central')
    Exports a timestamp to a single cell in the Google Sheet
    :param str cell:
    :param str fmt: (default "%Y-%m-%d %H:%M %Z")
    :param str tz: (default "US/Central")

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java将Scanner对象作为构造函数参数传递给UserInterface类   spring未能启动bean“subtocolWebSocketHandler”;嵌套的例外是java。lang.IllegalArgumentException:没有处理程序   Java EE应用程序中后台服务的多线程Java线程(设置守护进程和优先级)?   java Pull to refresh返回列表的第一个位置   无法将comparator类转换为java。可比的   java将json从servlet传递到dojo   JavaHibernate:将子类实例转换为超类实例   java警告调用servlet类时非法反射访问   java静态变量值   java@Entity和@embeddeble之间有什么区别   java将作业配置导入公共作业配置类(注释配置)   sql公共表表达式(以values语句开头)在java中给出错误   java在ImageJ中使用ImageProcessor   java PostgreSQL executeBatch()会随着时间的推移而变慢   java在安卓中以表格形式排列sqllite表数据?   java中SVG的swing定制呈现   java删除与另一个实体映射的实体   java何时/如何添加ListView适配器,使用back按钮恢复它?(片段)   java为什么IBinder和Binder之间的类型转换不是非法的?   java在方法参数列表中使用ArrayList或List