2014-02-21 59 views
1

我正在嘗試編寫一個腳本來將電子表格列標題轉換爲表單中的問題。我希望能夠在電子表格所在的文件夾中運行此腳本,並讓它在相同的文件夾中創建表單。問題是,無論我放置腳本的位置如何,表單都會在根文件夾中創建。我在Form和FormApp文檔中找不到任何幫助。我敢肯定它只是一個簡單的MOD的函數調用,但是......使用腳本在非根文件夾中創建窗體

function createForm() 
{ 
    // Create a new form, then add a checkbox question, a multiple choice question, 
// a page break, then a date question and a grid of questions. 
var form = FormApp.create('New Form'); 
var form = FormApp.create('Form Name'); 
var item = form.addCheckboxItem(); 
item.setTitle('This is a bunch of gibberish!!!!!!!!!!!!'); 
item.setChoices([ 
     item.createChoice('Relish') 
    ]); 
Logger.log('Published URL: ' + form.getPublishedUrl()); 
Logger.log('Editor URL: ' + form.getEditUrl()); 
} 

回答

2

一個快速和骯髒的解決辦法是以下幾點:

function createForm(){ 
//get the form file through id of the form you just made 
var form  = FormApp.create('tempForm'), 
    id  = form.getId(), 
    formFile = DriveApp.getFileById(id); 
//get the id of the folder you want to move the form to 
var folderId = DriveApp.getFolderById('folderID'); 
//delete the temporary form 
formFile.setTrashed(true); 
//copy the temp form (still active) to the destination folder, open it. 
var newId = formFile.makeCopy(folder).setName('myCopiedForm').getId(), 
    form  = FormApp.openById(newId); 
} 

這是骯髒的,但它的工作原理。如果有更好的解決方案,請告訴我。

相關問題