Skip to content

Instantly share code, notes, and snippets.

@pjhoberman
Created March 20, 2015 19:21
Show Gist options
  • Save pjhoberman/bd41791c4b22e3fa21d1 to your computer and use it in GitHub Desktop.
Save pjhoberman/bd41791c4b22e3fa21d1 to your computer and use it in GitHub Desktop.
function expand() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh0 = ss.getSheets()[0], sh1 = ss.getSheets()[1], row_counter = 1;
// get data
var data = sh0.getDataRange().getValues();
for(var i in data){
// APN
var apn = data[i][8];
if(typeof apn == "string"){ // it's a string, let's split and iterate
var apns = apn.split(",");
var r = apns.length; // how many apn rows?
for(var j=0; j<r; j++){ // loop through that row
for(var k=0;k<data[i].length;k++){ // set up the columns
if(k==9){ // set APN
sh1.getRange(row_counter, 10, 1, 1).setValue(apns[j]);
} else if(j>0 && k==10) { // ignore acreage
sh1.getRange(row_counter, 11, 1, 1).setValue("");
} else { // fill in the rest
sh1.getRange(row_counter, k+1, 1, 1).setValue(data[i][k]); // copy and paste the rows
}
}
row_counter++;
}
}
else { // it's not, let's just copy it over
for(var k=0;k<data[i].length;k++){
sh1.getRange(row_counter, k+1, 1, 1).setValue(data[i][k]);
}
row_counter++;
// sh1.getRange(row_counter, 1, 1, data[i].length).setValues(data[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment