按名称打开Google Apps电子表格 [英] Open Google Apps Spreadsheet by name
问题描述
我每天使用脚本创建一个新的Google Spreadsheet.我敢肯定驱动器上只有一个具有该名称的电子表格,因为在创建新电子表格之前,我会丢弃所有具有相同名称的电子表格.
但是如何使用Google Apps脚本打开电子表格?我没有该文件的ID.我有一个小脚本,所以我可以找到该文件:
function myFunction(){//在用户的云端硬盘中记录每个文件的名称.var files = DriveApp.getFilesByName('datafile');while(files.hasNext()){var file = files.next();Logger.log(file.getName());}}
是否完全可以使用脚本打开此电子表格?我想每天将它作为csv文件下载到服务器上.
在创建电子表格时,您可以使用 PropertiesService
存储电子表格的ID:
var id = newSS.getId();//其中newSS是您的新电子表格PropertiesService.getScriptProperties().setProperty('id',id);
然后可以在需要时调用存储的属性:
PropertiesService.getScriptProperties().getProperty('id');
有关更多信息,请查看 PropertiesService 文档.
With a script I create a new Google Spreadsheet every day. I'm certain there is only one spreadsheet on the drive with this name, as I trash everything with the same name before creating a new one.
But how can I open the spreadsheet with google apps script? I have no ID for the file. I have a small script so I can find the file:
function myFunction() {
// Log the name of every file in the user's Drive.
var files = DriveApp.getFilesByName('datafile');
while (files.hasNext()) {
var file = files.next();
Logger.log(file.getName());
}
}
Is it possible to open this spreadsheet at all with a script? I want to download it everyday on a server as csv file..
You can use the PropertiesService
to store the id of the spreadsheet when you create it:
var id = newSS.getId(); //where newSS is your new spreadsheet
PropertiesService.getScriptProperties().setProperty('id', id);
You can then call the stored property when you want it:
PropertiesService.getScriptProperties().getProperty('id');
For more information, check out the PropertiesService documentation.
这篇关于按名称打开Google Apps电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!