gpt4 book ai didi

javascript - G脚本: List and Filter G-Drive Files from Variables Stored in a G-Sheet

转载 作者:行者123 更新时间:2023-11-30 13:51:03 26 4
gpt4 key购买 nike

我尝试使用过滤器列出 G-Drive 中的文件。过滤器变量存储在 G-Sheet 中。

代码来了。这是行不通的。但是当我放置文本字符串而不是变量时它会起作用。

非常感谢,

function Lister_fichiers() {
// Log the name of every file in the user's Drive that modified after date = 'Var!'A1,
// whose name contains "MARQUE = 'Var!'B1".
var app = SpreadsheetApp;
var classeur = app.getActiveSpreadsheet();

const Formsheet = classeur.getSheetByName('Var');
const CsvM = classeur.getSheetByName('CsvM');

var Date1 = Formsheet.getRange('A1').getValue();
var Date2 = new Date(Date.UTC(Date1));

var Marque = Formsheet.getRange('B1').getValue();
var Pays = Formsheet.getRange('C1').getValue();

// this line here does not work and causes an error
var sffiles = DriveApp.searchFiles("modifiedDate > '"+Date2+"' and title contains '"+Marque+"' ");
}

此外,它没有错误,但在没有日期过滤器的情况下仍然无法工作。

在工作表中,A1 = "2019-01-01"和 B1 = "Marque1"

//下面的行工作正常

// var sffiles = DriveApp.searchFiles('modifiedDate > "2019-01-01" and title contains "Marque1" and mimeType = "application/vnd.google-apps.spreadsheet" and trashed=false');


while (sffiles.hasNext()){
var sffile = sffiles.next();
var sfname = sffile.getName();
var sfdate = sffile.getLastUpdated();
var sfsize = sffile.getSize();
var sfurl = sffile.getUrl();
var fileParents = sffile.getParents();
while (fileParents.hasNext()) {
var sffolder = fileParents.next();
Logger.log(sffolder.getName());
}
var sfid = sffile.getId();
Logger.log(sffile.getId());
Logger.log(sffile.getName());

var sflist = [sfname,sfdate,sfsize,sfurl,sfid,sffolder];
CsvM.appendRow(sflist);
}
CsvM.appendRow(["A-Name", "Date", "Size", "URL", "ID", "Dossier Parent"]);
CsvM.sort(1);
}

最佳答案

确切的错误消息是什么?我怀疑问题出在这一行:

var Date2 = new Date(Date.UTC(Date1));

如果 var Date1 A1 是“2019-01-01”,你应该能够做到:

var Date2 = new Date(Date1)

它为您提供日期时间对象。

我认为混淆是您可以将像“2019-01-01”这样的字符串传递给 new Date() [0] 但不能传递给 Date.UTC() [1]

[0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC

关于javascript - G脚本: List and Filter G-Drive Files from Variables Stored in a G-Sheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58239414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com