I have a problem writing a script for a google sheet. I want to get the column header name to the application.
For getting another cell:
I am using this script:
}
//READ SINGLE RECORD
else if ( e.parameter.func == "ReadRecord") {
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheets()[0];
var rg = sh.getDataRange().getValues();
var outString = '';
outString += rg[parseInt(e.parameter.id)].join(',');
return ContentService.createTextOutput(outString).setMimeType(ContentService.MimeType.TEXT);
}
Please help.
//RETURN ALL DATA and HEADINGS
else if ( e.parameter.func == "AllData") {
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheets()[0];
var rg = sh.getDataRange().getValues();
return ContentService.createTextOutput(JSON.stringify(rg));
This should return a stringified json array (list of lists) of all the data on the sheet, including your column headings
or if you only want the column headings
//GET HEADINGS ROW
else if ( e.parameter.func == "GetHeadings") {
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheets()[0];
var rg = sh.getDataRange().getValues();
return ContentService.createTextOutput(rg[0]);
If you just want a specific column header (in your screenshot you have highlighted column C)
//GET HEADING
else if ( e.parameter.func == "GetHeading") {
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheets()[0];
var rg = sh.getDataRange().getValues();
return ContentService.createTextOutput(rg[0][2]);