Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 在searchFiles Google脚本中使用变量_Google Apps Script_Google Sheets_Google Sheets Query - Fatal编程技术网

Google apps script 在searchFiles Google脚本中使用变量

Google apps script 在searchFiles Google脚本中使用变量,google-apps-script,google-sheets,google-sheets-query,Google Apps Script,Google Sheets,Google Sheets Query,我有一个第三方程序,它将每日数据拉入CSV文件,文件名从运行日期开始,例如17072017filename.CSV 我需要一个单独的电子表格,将采取从用户的日期输入,然后将搜索在驱动器中的文件,直到它匹配的CSV文件上的日期。找到所需文件后,我可以使用getFileID()和getRange()从该CSV文件复制各种值。 这就是我目前拥有的(电子表格中的单元格A2是用户可以键入他们想要的日期的地方,例如17072017) 问题似乎是我无法在searchFiles()中将日期(每天都会更改)作为变

我有一个第三方程序,它将每日数据拉入CSV文件,文件名从运行日期开始,例如17072017filename.CSV 我需要一个单独的电子表格,将采取从用户的日期输入,然后将搜索在驱动器中的文件,直到它匹配的CSV文件上的日期。找到所需文件后,我可以使用getFileID()和getRange()从该CSV文件复制各种值。 这就是我目前拥有的(电子表格中的单元格A2是用户可以键入他们想要的日期的地方,例如17072017)

问题似乎是我无法在searchFiles()中将日期(每天都会更改)作为变量传递。这可能吗? 这就是我目前所拥有的

function myfunction()
{
    var inputDate = SpreadsheetApp.getActiveSheet().getRange("A2").getValue();
    var files = DriveApp.searchFiles('title contains 'inputDate'');
    while (files.hasNext()) 
    {
        var file = files.next();
        Logger.log(file.getName());
    }
}

下面的修改怎么样

发件人: 致:
如果我误解了你的问题,我很抱歉。

这似乎行得通。“加号”对变量inputDate有什么作用?我想我真的被单引号和双引号弄糊涂了,但是谢谢你的帮助me@Gramps欢迎也谢谢你。使用
+
,将
inputDate
title包含的字符串进行求和。
var files = DriveApp.searchFiles('title contains 'inputDate'');
var files = DriveApp.searchFiles("title contains '" + inputDate + "'");