2014-10-04 136 views
0

我想創建一個包含圖片上傳字段的數據收集表單。我嘗試了谷歌表格,它本身不支持文件上傳,但我發現這個例子:Form and file upload with htmlService and app script not working使用Google Apps腳本的自定義表單的提交時間戳

我設法配置它與圖片上傳,但本地谷歌表格確實有電子表格響應時間戳列。

我想:

var timestamp = theForm.getTimestamp();

但沒有工作......

我怎樣才能得到響應時間戳?

代碼摘錄:

function processForm(theForm) { 
    var fileBlob = theForm.myFile; 
    var folder = DriveApp.getFolderById(folderId); 
    var doc = folder.createFile(fileBlob); 

    // Fill in response template 
    var template = HtmlService.createTemplateFromFile('Thanks.html'); 

    var name = template.name = theForm.name; 
    var email = template.email = theForm.email; 
    var timestamp = template.timestamp = theForm.getTimestamp(); 

    // Record submission in spreadsheet 
    var sheet = SpreadsheetApp.openById(submissionSSKey).getSheets()[0]; 
    var lastRow = sheet.getLastRow(); 
    var targetRange = sheet.getRange(lastRow+1, 1, 1, 5).setValues([[timestamp,name,department,message,email,fileUrl]]); 

    // Return HTML text for display in page. 
    return template.evaluate().getContent(); 
} 

回答

4

HTML表單不會自動傳遞任何時間戳在服務器提交,像谷歌表單做。你將不得不自己生成時間戳。 new Date()會做你想要什麼:

var timestamp = template.timestamp = new Date(); 

如果需要輸出在你的頁面此Date對象屏幕,您將需要使它人類可讀通過格式化。您可以使用Utilities.formatDate() method來執行此操作。

+0

工作,謝謝。但是,這不是客戶端時間戳嗎? – Silva 2014-10-04 19:36:57

+1

不,.gs Google Apps腳本文件在服務器上進行處理和執行,而不是在客戶端的瀏覽器中執行。所以時間戳將是服務器時間戳。您應確保您的GAS項目在菜單文件 - >項目屬性下_Info_選項卡上選擇了正確的時區。 – azawaza 2014-10-06 18:32:21

+0

哦,謝謝你的信息。我沒有使用GAS的經驗。謝謝! – Silva 2014-10-07 20:59:32

相關問題