Created
July 4, 2013 11:07
-
-
Save roundrop/5926836 to your computer and use it in GitHub Desktop.
GroovyからGoogle Spreadsheetに何かを書き込むってのを書いてみた
参考: https://gist.github.com/cho45/4222750
GETでリクエストするのであまり大量のデータは書き込めない
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
: | |
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