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¶
To use these operators, you must do a few things:
Select or create a Cloud Platform project using the Cloud Console.
Enable billing for your project, as described in the Google Cloud documentation.
Enable the API, as described in the Cloud Console documentation.
Install API libraries via pip.
pip install 'apache-airflow[google]'Detailed information is available for Installation.
Create spreadsheet¶
To create new spreadsheet you can use the
GoogleSheetsCreateSpreadsheetOperator
.
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:
print_spreadsheet_url = BashOperator(
task_id="print_spreadsheet_url",
bash_command=f"echo {XComArg(create_spreadsheet, key='spreadsheet_url')}",
)