Google Spreadsheet Post #2024
How to generate new rows from multiple comma-separated values in a single column
Yogi Anand, D.Eng, P.E. ANAND Enterprises LLC -- Rochester Hills MI www.energyefficientbuild.com. Jan-18-2016
post by: Training Development Changi Airport:
https://productforums.google.com/forum/#!topic/docs/NL7QojMMoYs;context-place=forum/docsHow to generate new rows from multiple comma-separated values in a single column
Hi, I do not have any programming background in JavaScript but have been attempting to do the Apps Script to write codes based on what I read online.
I have reached a roadblock on one of the posts by Martin Hawksey on "Data Shaping in Google Spreadsheet – Generating New Rows from Multiple Values in a Single Column" (https://mashe.hawksey.info/ category/mooc/page/4/).
Basically I need to do exactly what he did in his article, and I have my spreadsheet here https://docs.google.com/ spreadsheets/d/ 1gqB4qZOvBXDBITZaxDfe8pUmx3EOb LiUcIzmZ1U1xLg/edit?usp= sharing
In the tab Form Responses 2, I have a Google form linked to it whereby people can enter multiple names by separating them with commas. I need to generate new rows from each name, and have the other columns and their contents duplicated into the corresponding rows. However when I try to use the below code, I am still unable to obtain the new rows with each name.
Is anyone kind enough to assist?
function splitColumnAndRepeatRows( anArray, splitColumnIndex) {
var output = [];
for (var i = 0; i < anArray.length; i++) { // for each row
var splitArray = anArray[i][splitColumnIndex]. toString().split("\n"); // split values in specified column
for (var j = 0; j < splitArray.length; j++) { // for each split cell value
if (splitArray[j] == "" && j >= 1)
continue;
var row = anArray[i].slice(0); // take a copy of source row
row[splitColumnIndex] = splitArray[j];
output.push(row); // push new row to output
}
}
return output;
}
var output = [];
for (var i = 0; i < anArray.length; i++) { // for each row
var splitArray = anArray[i][splitColumnIndex].
for (var j = 0; j < splitArray.length; j++) { // for each split cell value
if (splitArray[j] == "" && j >= 1)
continue;
var row = anArray[i].slice(0); // take a copy of source row
row[splitColumnIndex] = splitArray[j];
output.push(row); // push new row to output
}
}
return output;
}
------------------------------------------------------------------------------------
No comments:
Post a Comment