2016-05-31 51 views

回答

1

是的,這是可能的。我會這樣做creating an Apps Scriptdeploying it as a web app。以下是示例腳本:填寫Id of the spreadsheet及其中一張表的名稱。

function doPost(event) { 
    var params = event.parameter; 
    var sheet = SpreadsheetApp.openById('..Id..').getSheetByName('..Name..'); 
    if (params.data !== undefined) { 
    sheet.getRange(1, 1).setValue(params.data); 
    return ContentService.createTextOutput("Success"); 
    } 
    else { 
    return ContentService.createTextOutput("Oops"); 
    } 
} 

將腳本發佈爲Web應用程序,允許訪問每個人(除非您想處理認證)。這會給你一個URL,如https://script.google.com/macros/s/..../exec

在客戶端,你發送POST請求到該URL。腳本希望數據在參數「數據」中。

var url = 'https://script.google.com/macros/s/..../exec'; 
$.post(url, {data: 'hello world'}); 

(我使用jQuery這裏只是爲了有一個較短的例子,你可以發送普通的JavaScript POST請求。)

細胞您選擇紙張的A1將有「世界你好」 。

+0

這是我需要的。謝謝! – Erik

+0

我剛剛得到CORS問題。當我向外域發送POST請求時,瀏覽器會限制這一點。如何解決這個問題? – Erik

相關問題