【问题标题】:I need to migrate this Doclist code to Drivapp, but couldn't我需要将此 Doclist 代码迁移到 Drivapp,但不能
【发布时间】:2015-04-30 13:07:34
【问题描述】:

我刚刚尝试用 Driveapp 替换 Doclist 以执行带有参数 (num,num) 的文件搜索,但它返回错误:invalid method getFiles(num,num)

function b(e) {
  var app = UiApp.getActiveApplication();

  var resultado = ""
  var urlBase = "https://docs.google.com/a/escuelasanpedro.com/file/d/";
  var doc = DocsList.getFolderById("0B8p4BFVjx9pDZXFIYUQzSFZqeFE").getFiles(0,500)
  var idDoc =""
  var nombre =""
  for ( var i = 1; i < doc.length;i++) { 
       if (e.parameter.userName == doc[i].getName().substring(0,doc[i].getName().indexOf("."))) { 
          idDoc = doc[i].getId()
          nombre = e.parameter.userName
          resultado = urlBase + idDoc ;
          }
       }  

我尝试了以下代码,但收到消息“在迭代器对象中找不到函数'getname'”

function b(e) {
  var app = UiApp.getActiveApplication();
//serverhandler, proceso real

  var resultado = ""
  var urlBase = "https://docs.google.com/a/escuelasanpedro.com/file/d/";

  var doc = DriveApp.getFolderById("0B8p4BFVjx9pDZXFIYUQzSFZqeFE").getFiles()
  var idDoc =""
  var nombre =""

 while (doc.hasNext()) {
   var file = doc.next();
       if (e.parameter.userName == doc.getName().substring(0,doc.getName().indexOf("."))) { 
          idDoc = doc.getId()
          nombre = e.parameter.userName
          resultado = urlBase + idDoc ;
       }
 }

【问题讨论】:

  • @snickers10m 哪些外部库?没看到
  • 请查看有关如何使用driveapp的文档。

标签: google-apps-script


【解决方案1】:

您几乎明白了...您的 doc 变量是迭代器,名为 file 的新变量是实际文件,但您不使用它。

像这样更新:

 while (doc.hasNext()) { 
 var file = doc.next();
 if (e.parameter.userName == file.getName().substring(0,file.getName().indexOf("."))) { idDoc = file.getId()

【讨论】:

  • 谢谢,它工作得很好。我需要一个可以找到更多 driveApp 示例的链接,这太棒了!
  • 请考虑接受答案。谢谢。这个网站上有例子,但我建议你试着看看它的逻辑,然后你就不需要例子了。
猜你喜欢
  • 2015-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-19
  • 1970-01-01
  • 2020-05-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多