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

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

问题描述

我有一种情况,脚本正在输入数据并将其发送到电子表格。过了一会儿,这张电子表格变得太大了。

现在我们必须手动将项目从主电子表格移动到新电子表格。原因是不是每个人都熟悉代码,并且愿意更改代码中的ID。

我想知道是否有办法按名称打开电子表格。如果没有,是否有更好的方式来实现我们需要的内容(如上所述)?解决方案

更新:DocsList现在已经日落。使用 DriveApp.getFilesByName(






David提供了一些很好的代码来洗牌周围的数据。如果你真的需要的只是通过名字打开一个电子表格,那么这将做到这一点:

  function getSpreadsheetByName(filename) {
var files = DocsList.find(filename);

for(var i in files)
{
if(files [i] .getName()== filename)
{
// open - 无证函数
返回SpreadsheetApp.open(files [i]);
// openById - 记录但更详细的
//返回SpreadsheetApp.openById(files [i] .getId());
}
}
返回null;
}


I have a situation where a script is taking input data and sending it to a spreadsheet. After a while, this spreadsheet becomes too big.

Right now we have to manually move the items from the the primary spreadsheet to a new one. The reason is that not everyone is familiar with the code and are willing to change the ID in the code.

I would like to know if there is a way to open the spreadsheet by name. If not, is there a better way of achieving what we need (described above)

解决方案

Update: DocsList has now been sunset. Use DriveApp.getFilesByName(name) instead.


David has provided some good code for shuffling your data around. If all you really did need was just to open a spreadsheet by name then this will do the trick:

function getSpreadsheetByName(filename) {
  var files = DocsList.find(filename);

  for(var i in files)
  {
    if(files[i].getName() == filename)
    {
      // open - undocumented function
      return SpreadsheetApp.open(files[i]);
      // openById - documented but more verbose
      // return SpreadsheetApp.openById(files[i].getId());
    }
  }
  return null;
}

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

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