Skip to content

Instantly share code, notes, and snippets.

@atomer
Created September 12, 2011 14:22
Show Gist options
  • Save atomer/1211373 to your computer and use it in GitHub Desktop.
Save atomer/1211373 to your computer and use it in GitHub Desktop.
GDD2011 DevQuiz Google Apps Script
function myFunction() {
var res, data, ss, ass, sheet, cell, c, u, r, idx;
// 入力データの読み込み及びJSONデータのパース
res = UrlFetchApp.fetch("http://gdd-2011-quiz-japan.appspot.com/apps_script/data?param=2033167385065124336");
data = Utilities.jsonParse(res.getContentText());
// スプレッドシートの取得
ss = SpreadsheetApp.getActiveSpreadsheet();
for (var i = 0, ilen = data.length; i < ilen; i++) {
sheet = ss.insertSheet(data[i].city_name);
for (var j = 0, jlen = data[i].data.length; j < jlen; j++) {
c = data[i].data[j].capacity;
u = data[i].data[j].usage;
idx = j + 1;
r = u / c * 100;
sheet.getRange("A" + idx).setValue(c);
sheet.getRange("B" + idx).setValue(u);
cell = sheet.getRange("C" + idx);
cell.setNumberFormat("##.00%");
cell.setValue(r);
}
}
// デフォルトのシートの削除
ass = ss.getSheets()[0];
if (ass.getName() === "シート1") {
ass.activate();
ss.deleteActiveSheet();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment