Skip to content

Instantly share code, notes, and snippets.

@roundrop
Created July 4, 2013 11:07
Show Gist options
  • Save roundrop/5926836 to your computer and use it in GitHub Desktop.
Save roundrop/5926836 to your computer and use it in GitHub Desktop.
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