【发布时间】:2014-02-03 20:36:51
【问题描述】:
我找到了一个脚本,可以将我的电子表格移动到一个文件夹中。我怎样才能使它在电子表格打开时运行函数。我将把它应用到模板上,这样每次打开模板时,电子表格文件的“副本”都会自动移动到我的装箱单文件夹中。
这是我的代码......
function MoveFileTo()
{
var docs=DocsList.find('Save Test');
var doc=docs[0]; /*Since we assume there is only one file with the name "Hello World", we take the index 0 */
var folders = doc.getParents();
var newFolder=DocsList.getFolder('Packing Lists');
doc.addToFolder(newFolder); // This will add the document to its new location.
var docParentFolder=folders[0];
doc.removeFromFolder(docParentFolder); // This will remove the document from its original location.
}
编辑:我尝试将函数 MoveFileTo 更改为 onOpen() 和 onEdit(),但它似乎无法正常工作。有什么我遗漏的吗?
【问题讨论】:
-
见:stackoverflow.com/questions/17158179/…。您可能会在第一个答案中找到答案。
标签: google-apps-script google-sheets google-drive-api