Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
GroovyからGoogle Spreadsheetに何かを書き込むってのを書いてみた 参考: https://gist.github.com/cho45/4222750 GETでリクエストするのであまり大量のデータは書き込めない
function doGet(req) {
var result = { ok : 0 };
if (req.parameters.api_key == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') {
var rows = [];
try { rows = JSON.parse(req.parameters.rows) } catch (e) { }
if (rows.length) {
var ss = SpreadsheetApp.openById('*****************************************');
var sheet = ss.getSheets()[0];
for (var i = 0, len = rows.length; i < len; i++) {
sheet.appendRow(rows[i]);
result.ok++;
}
}
}
return ContentService.createTextOutput(JSON.stringify(result))
.setMimeType(ContentService.MimeType.JSON);
}
:
def rows = new ArrayList()
result.metadata.fields.each{
rows.add([it.name, it.description])
}
def gas_url = "https://script.google.com/macros/s/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz/exec"
def res = new URL(gas_url + "?" +
[
"api_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"rows" : URLEncoder.encode(rows.toString(), "UTF-8")
].collect { it.key + "=" + it.value }.join("&")
).text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment