2017-04-10 71 views
0

我想通过google脚本自动化以下步骤。 Google表格 - >文件 - >下载为 - > Microsoft Excel 我想将我的硬盘上的文件保存到特定的文件夹中。通过脚本自动将Google表格下载到特定的文件夹中

如何使用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****** 
} 

感谢您的帮助!

+0

为什么Excel标签?我想我知道Excel,但我无法回答这个问题。 –

回答

0
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 
} 

你不能从脚本您的硬盘保存,但您可以通过电子邮件给自己发送或保存它会让你的硬盘帐户(并从PC驱动器的应用程序得到它在您的计算机上/苹果电脑)。

您可以使用UrlFetchApp类获取您的URL字符串的响应。之后,您使用DriveApp的createFile(blob)方法为您的云端硬盘的根目录创建一个文件。详细了解DriveApp类别以将文件移动到所需的文件夹上。

+0

我不知道我无法定义硬盘位置。谢谢。 – Erika