Skip to content

Instantly share code, notes, and snippets.

@falms
Created September 14, 2011 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save falms/1216373 to your computer and use it in GitHub Desktop.
Save falms/1216373 to your computer and use it in GitHub Desktop.
(4) Google Apps Script
function myFunction() {
var d = [
{
"city_name": "Oykot",
"data": [
{
"capacity": 1000,
"usage": 750,
},
{
"capacity": 1200,
"usage": 1000,
},
{
"capacity": 800,
"usage": 400,
},
]
},
{
"city_name": "Akaso",
"data": [
{
"capacity": 1000,
"usage": 790,
},
]
},
]
;
var ss = SpreadsheetApp.getActiveSpreadsheet();
for(i=0; i<d.length; i++){
ss.insertSheet(d[i]["city_name"],i);
for(j=0; j<d[i]["data"].length; j++){
ss.setActiveCell("A"+(j+1)).setValue(d[i]["data"][j]["capacity"]);
ss.setActiveCell("B"+(j+1)).setValue(d[i]["data"][j]["usage"]);
ss.setActiveCell("C"+(j+1)).setValue(d[i]["data"][j]["usage"]/d[i]["data"][j]["capacity"]*100 + "%");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment