我已经编写了这个脚本来搜索特定用户拥有的文件 - 除了这个函数之外,它工作得很好,返回所有结果,并且链接被设置为像doc一样打开。所以pdf和其他文件因为URL错误而导致错误打开。有没有通用的方法来打开文件,还是我需要编写if语句?关于如何解决这个问题的任何可能的想法?感谢
function handleResults(results){
console.log('Handle Results was called! ');
document.writeln('<a href="https://script.google.com/a/macros/35634534534534534534534534534">BACK</a><br/><br/>');
var length=results.length; // total elements of results
for(var i=0;i<length;i++)
{
var item=results[i];
item=item.split("|~|"); // split the line |~|, position 0 has the filename and 1 the file id
document.writeln("<b><a href='https://docs.google.com/document/d/"+item[1]+"' target='_blank'>"+item[0]+"</b></a> (Last modified: "+item[2]+")<br/><br/>"); // write result
}
document.writeln("End of results...");
}
答案 0 :(得分:0)
感谢@spiderPig使用File.getUrl();
function handleResults(results){
console.log('Handle Results was called! ');
document.writeln('<a href="https://script.google.com/a/macros/35634534534534534534534534534">BACK</a><br/><br/>');
var length=results.length; // total elements of results
for(var i=0;i<length;i++)
{
var item=results[i];
item=item.split("|~|"); // split the line |~|, position 0 has the filename and 1 the file URL
// i changed item1 to contain the file.getUrl instead of the fileId
document.writeln("<b><a href='"+item[1]+"' target='_blank'>"+item[0]+"</b></a> (Last modified: "+item[2]+")<br/><br/>"); // write result
}
document.writeln("End of results...");
}