按名称打开Goog​​le Apps电子表格 [英] Open Google Apps Spreadsheet by name

查看:52
本文介绍了按名称打开Goog​​le Apps电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每天使用脚本创建一个新的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.

这篇关于按名称打开Goog​​le Apps电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆