我正在尝试根据 Google 应用中的一些用户信息生成文档。
我有类似下面的代码(简化):
var titleAndPath = "./some/other/path/bar.doc"
var info = "foo";
var currentDoc = DocumentApp.create(titleAndPath);
var title = currentDoc.appendParagraph(info);
但是,除了“根”Google 云端硬盘目录外,我实际上似乎无法保存任何内容。换句话说,我想将文档保存在某个子文件夹中。 google API 有这个功能吗?我检查了文档 API 无济于事 ( https://developers.google.com/apps-script/class_document#saveAndClose )。
希望这个没有我担心的那么明显!
提前致谢。
最佳答案
当您调用 DocumentApp.create 时,路径的概念不存在,即斜线和点被解释为文件名中的另一个字符。您需要做的是使用 DriveApp与 DocumentApp 类一起上课。这看起来像以下内容(未经测试):
var title = "bar.doc";
var doc = DocumentApp.create ( title );
var docId = doc.getId (); // retrieve the document unique id
var docFile = DriveApp.getFileById ( docId ); // then get the corresponding file
// Use the DriveApp folder creation and navigation mechanisms either:
// - to get to your existing folder, or
// - to create the folder path you need.
var folder = …
folder.addFile ( docFile );
关于javascript - 谷歌应用指定创建文档的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14265970/