簡體   English   中英

通過腳本自動將 Google Sheet 下載到特定文件夾中

[英]Automatically download Google Sheet into a specific folder by script

我想通過谷歌腳本自動化以下步驟。 Google 表格 -> 文件 -> 下載為 -> Microsoft Excel 我想將硬盤驅動器上的文件保存到特定文件夾中。

如何使用 google 腳本自動執行此任務?

function downloadXLSX() {
  var ssID = SpreadsheetApp.getActive().getId();
  var URL = 'https://docs.google.com/spreadsheets/d/'+ssID+'/export?format=xlsx';
  *******HERE SHOULD BE THE PART TO DOWNLOAD INTO THE SPECIFIC FOLDER******
}

謝謝您的幫助!

function downloadXLSX() {
  var ssID = SpreadsheetApp.getActive().getId();
  var URL = 'https://docs.google.com/spreadsheets/d/'+ssID+'/export?format=xlsx';
  var blob;
  var response = "";
  var token = ScriptApp.getOAuthToken();

  response = UrlFetchApp.fetch(URL, {
    headers: {
      'Authorization': 'Bearer ' +  token
    }
  });

  blob = response.getBlob().setName('document.xlsx');// Convert the response to a blob 

  DriveApp.createFile(blob); // Create a file with the blob and place it to Drive's root
}

您無法從腳本保存在硬盤上,但您可以通過電子郵件發送給自己或保存它並拋出您的 Drive 帳戶(並通過 PC/MAC 上的 Drive 應用程序將其保存到您的計算機上)。

您可以使用UrlFetchApp 類來獲取 URL 字符串的響應。 之后,您使用 DriveApp 中的createFile(blob)方法創建一個文件到 Drive 的根目錄。 查看有關DriveApp 類的更多信息以將文件移動到所需的文件夾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM