Created
September 12, 2011 14:22
-
-
Save atomer/1211373 to your computer and use it in GitHub Desktop.
GDD2011 DevQuiz Google Apps Script
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 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