Google Sheets 至 Google Cloud Storage 傳輸運算子¶
Google 提供一項服務 Google Cloud Storage。此服務用於儲存來自各種應用程式的大量資料。
透過 Google Sheets,所有人都可以同時在同一個試算表中協同作業。使用公式、函數和格式設定選項來節省時間並簡化常見的試算表任務。
先決條件任務¶
若要使用這些運算子,您必須完成幾件事
使用 Cloud Console 選取或建立 Cloud Platform 專案。
為您的專案啟用帳單功能,如 Google Cloud 文件 中所述。
啟用 API,如 Cloud Console 文件 中所述。
透過 pip 安裝 API 程式庫。
pip install 'apache-airflow[google]'詳細資訊請參閱 安裝。
從 Google Sheets 上傳資料至 GCS¶
若要從 Google 試算表上傳資料至 Google Cloud Storage,您可以使用 GoogleSheetsToGCSOperator
。
upload_sheet_to_gcs = GoogleSheetsToGCSOperator(
task_id="upload_sheet_to_gcs",
destination_bucket=BUCKET_NAME,
spreadsheet_id="{{ task_instance.xcom_pull(task_ids='create_spreadsheet', "
"key='spreadsheet_id') }}",
gcp_conn_id=CONNECTION_ID,
)
您可以將 Jinja 模板 與 spreadsheet_id
、 destination_bucket
、 destination_path
、 sheet_filter
、 impersonation_chain
一起使用。