Google Sheets Operators

The latest version of the Sheets API lets developers programmatically:

  • Read and write data

  • Format text and numbers

  • Build pivot tables

  • Enforce cell validation

  • Set frozen rows

  • Adjust column sizes

  • Apply formulas

  • Create charts... and more!

For more information check official documentation.

Prerequisite Tasks

Create spreadsheet

To create new spreadsheet you can use the GoogleSheetsCreateSpreadsheetOperator.

airflow/providers/google/suite/example_dags/example_sheets.pyView Source

create_spreadsheet = GoogleSheetsCreateSpreadsheetOperator(
    task_id="create_spreadsheet", spreadsheet=SPREADSHEET
)

You can use Jinja templating with spreadsheet, impersonation_chain.

To get the URL of newly created spreadsheet use XCom value:

airflow/providers/google/suite/example_dags/example_sheets.pyView Source

print_spreadsheet_url = BashOperator(
    task_id="print_spreadsheet_url",
    bash_command=f"echo {create_spreadsheet.output['spreadsheet_url']}",
)

Was this entry helpful?