Export CSV data (multiple data) to Google Sheet

From our lists in Appinventor we create suitably formatted strings for each “column” (e.g. ID or NAME) and send the entire string to the webapp as a single parameter. You can of course pull in a csv file using the file component.
 

 
The webapp then converts these strings to javascript arrays, and then appends each set to the spreadsheet. You can create the web app as a bound script on the google sheet, as opposed to having a separate file.
 
My simple example only handles two columns of data, an ID and a NAME To add more amend the blocks in AppInventor and edit the web app script (remembering to republish!)
 
Modern browsers should be able to cope with very long uris, but I have put in a check on the response code just in case. I stress tested the method using a csv table of 6 columns and 100 entries, so 600 pieces of data. The sheet populated in under 5 seconds!
 
The BLOCKS
 
 
The Web App Code
 
function doGet(e) { 
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Sheet1");
uploadData(e,sheet);
}

function doPost(e) {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Sheet1");
uploadData(e,sheet);
}

function uploadData(e,sheet) {

var ids = eval("[" + e.parameters.ids + "]") ;
var names = eval("[" + e.parameters.names + "]") ;

for (var i=0;i<ids.length;i++) {
var id = ids[i];
var name = names[i];
sheet.appendRow([id,name]);
}
}

aia file:
GSMD

Leave a Reply

Your email address will not be published. Required fields are marked *