Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

How to transpose and split in Google Apps Script?

$
0
0

How do write script for below

google form response as below

time stampDocument No.Recipient NameDocument transmittal ref no
7/9/2021 21:36:11170709, 170738, 171769, 172003, 172025Susan20210001
7/18/2021 18:19:59131034, 131192, 132438, 132465, 133016Jhon20210002

i want processed data look like below

Time stampDocument no.Recipient NameDocument transmittal Ref no.
7/9/2021 21:36:11170709Susan20210001
7/9/2021 21:36:11170738Susan20210001
7/9/2021 21:36:11171769Susan20210001
7/9/2021 21:36:11172003Susan20210001
7/9/2021 21:36:11172025Susan20210001
7/18/2021 18:19:59131034Jhon20210002
7/18/2021 18:19:59131192Jhon20210002
7/18/2021 18:19:59132438Jhon20210002
7/18/2021 18:19:59132465Jhon20210002
7/18/2021 18:19:59133016Jhon20210002

the current script was done below

function formatData() { // File var ss = SpreadsheetApp.getActiveSpreadsheet(); // Get responseData sheet var rawData = ss.getSheetByName('documentTransmittal'); // Input data var data = rawData.getRange("A2:D").getValues(); // Gets titles and options in a single call to the sheet // Initialise an array that will hold the output var outputArray = []; // Name a variable to hold the data from each set of options var options; // Start looping through the data for (var row = 0; row < data.length; row++) { // Split the document with individual no. options = data[row][1].split(", "); // Loop through the array of split options and place each of them in a new row for (var element = 0; element < options.length; element++) { outputArray.push([data[row][0], // Place the title in a new row                  options[element]]); // Place one option in the 2nd column of the row  } // Options loop ends here } // Data loop ends here // Get processedData sheet var processedData = ss.getSheetByName('responseData'); // Get last row in processedData sheet var lastRow = processedData.getLastRow(); // Post the outputArray to the sheet in a single call processedData.getRange(lastRow + 1, 1, outputArray.length, outputArray[2].length).setValues(outputArray);}

above only can help get 2 row data only


Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>