2016-05-31 73 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

相关问题