Google apps script 从运行脚本的Google工作表中格式化Google Drive搜索查询名称[名字和姓氏]的最佳方式是什么?
我的google sheets脚本查询我的google drive文件夹,以返回与变量名[最早-最后]匹配的所有文档的文件名。以下是脚本:Google apps script 从运行脚本的Google工作表中格式化Google Drive搜索查询名称[名字和姓氏]的最佳方式是什么?,google-apps-script,google-sheets,google-drive-api,Google Apps Script,Google Sheets,Google Drive Api,我的google sheets脚本查询我的google drive文件夹,以返回与变量名[最早-最后]匹配的所有文档的文件名。以下是脚本: var search20 = sh1.getRange("B2").getValue(); var searchFor = 'title contains "JR"' + 'and fullText contains "' + search20 + '"'; Logger.log (searchFor); var names =[]; var files
var search20 = sh1.getRange("B2").getValue();
var searchFor = 'title contains "JR"' + 'and fullText contains "' + search20 + '"';
Logger.log (searchFor);
var names =[];
var files = DriveApp.searchFiles(searchFor);
while (files.hasNext()) {
var file = files.next();
var name = file.getName();
names.push(name);
for (var i = 0; i < names.length; i++) {
Logger.log(names[i]);
}
}
var search20=sh1.getRange(“B2”).getValue();
var searchFor='标题包含“JR”'+',全文包含“'+search20+'”;
Logger.log(searchFor);
变量名称=[];
var files=DriveApp.searchFiles(searchFor);
while(files.hasNext()){
var file=files.next();
var name=file.getName();
name.push(name);
对于(var i=0;i
我的剧本写得很好
我的问题:如何设置搜索条件的格式,以便脚本能够找到变量的所有实例(例如,我正在搜索的名称)并避免误报
脚本有时无法找到我知道包含我正在搜索的名称的文档
另一方面,脚本有时返回误报
当驱动器中的文档同时包含我要搜索的名字和姓氏,但不是连续出现时,就会出现误报
例如,我搜索“John Smith”,脚本返回一个包含名称的文档约翰·亚当斯
&
亚当·斯密 是否有可靠的搜索运算符可以工作?脚本不允许在名称周围添加引号 我试过约翰·史密斯,但没有成功 我和约翰/史密斯的合作很成功,但我仍然缺少那个接线员的一些文件
有什么想法吗?您是否查看了
搜索文件的文档?它链接到支持的语法,其中还包括几个示例和相关的注意事项。您希望通过搜索John Smith
来检索包含John Smith
内容的文档。如果我对您的问题的理解是正确的,那么修改为var searchFor='标题包含“JR”+,全文包含\''+search20+'”\''代码>?表示[2]如果运算符被双引号包围,则它包含与字母数字短语完全匹配的运算符。例如,如果文档的全文包含字符串“Hello there world”,则包含“Hello there”的查询全文将返回结果,但包含“Hello world”的查询全文将不返回结果。此外,由于搜索是字母数字的,如果文档全文包含字符串“Hello\u world”,则查询全文包含“Hello world”将返回结果。
将“\”添加到脚本搜索条件中有什么作用?谢谢你的建议。