Skip to content

04‐API

Teeraphat Kullanankanjana edited this page Oct 29, 2023 · 9 revisions

Import Library

from ggsheet import MicroGoogleSheet

Class Instance

MicroGoogleSheet(googleSheetURL, sheet_name, deploymentID)

Initializes the MicroGoogleSheet class with the Google Sheet URL, sheet name, and deployment ID.

Parameters

  • googleSheetURL(str): The URL of the Google Sheet.
  • sheet_name(str, optional): The name of the sheet within the Google Sheet. Default is "Sheet1".
  • deploymentID(str, optional): The deployment ID of the Google Apps Script web app. The default is an empty string, which can be added later with set_DeploymentID().
# Google Sheet Credential 
google_sheet_url = "https://docs.google.com/spreadsheets/d/xxxxxxxxx/edit#gid=0"
google_sheet_name = "Sheet1"
google_app_deployment_id = "xxxxxxxx"

# Create Instance 
ggsheet = MicroGoogleSheet(google_sheet_url,google_sheet_name,google_app_deployment_id)

Set Deployment ID

set_DeploymentID(deployment_id)

Sets the deployment ID for the Google Apps Script web app.

Parameters

  • deployment_id(str): The deployment ID to set.
# Google Sheet Credential 
google_sheet_url = "https://docs.google.com/spreadsheets/d/xxxxxxxxx/edit#gid=0"
google_sheet_name = "Sheet1"
google_app_deployment_id = "xxxxxxxx"

ggsheet = MicroGoogleSheet(google_sheet_url,google_sheet_name)
ggsheet.set_DeploymentID(google_app_deployment_id)

Set Sheet Name

set_SheetName(sheetName)

Sets the name of the sheet within the Google Sheet.

Parameters

  • sheetName (str): The sheet name to set.
# Google Sheet Credential 
google_sheet_url = "https://docs.google.com/spreadsheets/d/xxxxxxxxx/edit#gid=0"
google_sheet_name = "Sheet1"
google_app_deployment_id = "xxxxxxxx"

# Class Instance
ggsheet = MicroGoogleSheet(google_sheet_url,google_sheet_name)
# Set Deployment ID
ggsheet.set_DeploymentID(google_app_deployment_id)
# Set the sheet name from "Sheet1" to "Sheet2"
ggsheet.set_SheetName("Sheet2")

Generate Google Sheet Script

gen_scriptFile()

Generate a Google Apps Script file for Google Sheet operations.

Call this method in case you can't find the script.gs file.

# Google Sheet Credential 
google_sheet_url = "https://docs.google.com/spreadsheets/d/xxxxxxxxx/edit#gid=0"

# Class Instance
ggsheet = MicroGoogleSheet(google_sheet_url)

# Generate Google Script File
ggsheet.gen_scriptFile()

Update

Update the Google Sheet cell, row, or column.

The update will overwrite the old data.

Update Cell

updateCell(row,column,data)

Update the data to a specific cell.

Parameters

  • row (int): The row number of the cell.
  • column (int): The column number of the cell.
  • data (string): The data to set in the cell.

Update Row

updateRow(row,data)

Update the data in a specific row

Parameters

  • row (int): The row number to update.
  • data (list): A list of data values to update the row.

Update Column

updateColumn(column,data)

Update the data to a specific column

Parameters

  • column (int): The column number to update.
  • data (list): A list of data values to update the column.
# Google Sheet Credential 
google_sheet_url = "https://docs.google.com/spreadsheets/d/xxxxxxxxx/edit#gid=0"
google_sheet_name = "Sheet1"
google_app_deployment_id = "xxxxxxxx"

# Create Instance 
ggsheet = MicroGoogleSheet(google_sheet_url,google_sheet_name)
ggsheet.set_DeploymentID(google_app_deployment_id)

# Update the data to a specific cell 
ggsheet.updateCell(1,1,"Hello this is my first data")

# Update the data in a specific row 
ggsheet.updateRow(1,[3,2,1,"Row 1 Updated!"])

# Update the data to a specific column 
ggsheet.updateColumn(1,[3,2,1,"Column 1 Updated!"])

Get

Get the data from a specific Google Sheet cell, row, or column as a string or list.

Get Cell

getCell(row,column)

Get the data from a specific cell

** Parameters **

  • row (int): The column number to update.
  • column (int): A list of data values to update the column.

** Returns **

  • cell_data (str): The content of the specified cell.

Get Row

** getRow(row) **

Get all of the data from a specific row

** Parameters **

  • row (int): The column number to update.

** Returns **

  • row_data (list): The content of the specified row.

getColumn()

Python Code

Delete

Python Code

deleteCell()

Python Code

deleteRow()

Python Code

deleteColumn()

Python Code

Append

Python Code

appendCell()

Python Code

appendRow()

Python Code

appendColumn()

Python Code

Clone this wiki locally