2015-12-10 96 views
0

我想從HTML表單發佈到Google工作表。我目前只是試圖在Google App腳本中編寫代碼,但是一個錯誤提示「Script function not found:doGet」,我不知道該怎麼做。我的代碼如下:通過谷歌應用腳​​本發佈

function myFunction() { 
     var SHEET_NAME = "Sheet1"; 

var SCRIPT_PROP = PropertiesService.getScriptProperties(); // new property service 

function doGet(e){ 
    return handleResponse(e); 
} 

function doPost(e){ 
    return handleResponse(e); 
} 

function handleResponse(e) { 
    var lock = LockService.getPublicLock(); 
    lock.waitLock(30000); // wait 30 seconds before conceding defeat. 

    try { 
    var doc = SpreadsheetApp.openById(SCRIPT_PROP.getProperty("key")); 
    var sheet = doc.getSheetByName(SHEET_NAME); 

    var headRow = e.parameter.header_row || 1; 
    var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0]; 
    var nextRow = sheet.getLastRow()+1; // get next row 
    var row = []; 
    // loop through the header columns 
    for (i in headers){ 
     if (headers[i] == "Timestamp"){ // special case if you include a 'Timestamp' column 
     row.push(new Date()); 
     } else { // else use header name to get data 
     row.push(e.parameter[headers[i]]); 
     } 
    } 
    // more efficient to set values as [][] array than individually 
    sheet.getRange(nextRow, 1, 1, row.length).setValues([row]); 
    // return json success results 
    return ContentService 
      .createTextOutput(JSON.stringify({"result":"success", "row": nextRow})) 
      .setMimeType(ContentService.MimeType.JSON); 
    } catch(e){ 
    // if error return this 
    return ContentService 
      .createTextOutput(JSON.stringify({"result":"error", "error": e})) 
      .setMimeType(ContentService.MimeType.JSON); 
    } finally { //release lock 
    lock.releaseLock(); 
    } 
} 

function setup() { 
    var doc = SpreadsheetApp.getActiveSpreadsheet(); 
    SCRIPT_PROP.setProperty("key", doc.getId()); 
} 
} 

任何幫助將不勝感激。

回答

相關問題