2013-01-10 36 views
1

我正嘗試根據Google應用中的某些用戶信息生成文檔。谷歌應用指定創建文檔的路徑

我有類似如下的代碼(簡化):

var titleAndPath = "./some/other/path/bar.doc" 
var info = "foo"; 
var currentDoc = DocumentApp.create(titleAndPath); 
var title = currentDoc.appendParagraph(info); 

但是,我沒有真正似乎可以保存到任何東西,除了「根」谷歌驅動器目錄。換句話說,我想將文檔保存在一些子文件夾中。谷歌API是否有這個功能?我檢查了文檔API無濟於事(https://developers.google.com/apps-script/class_document#saveAndClose)。

希望這個不像我擔心的那樣顯而易見!

在此先感謝。

回答

2

當您調用DocumentApp.create時,path的概念不存在,即斜槓和點被解釋爲文件名中的另一個字符。您需要做的是將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);