exclude column from table range for html google app script

Viewed 148

I'm using app script to get an HTML page everything works fine except that I need to exclude column B+C from the range

function doGet() {
  return  HtmlService.createTemplateFromFile('Index').evaluate()
  .setTitle("Performance Efficiency");//We can set title from here

}
 
//GET DATA FROM GOOGLE SHEET AND RETURN AS AN ARRAY
 function getData() {
  var spreadSheetId = "Sheet ID"; //CHANGE
  var dataRange = "Data!A3:P"; //CHANGE

  var range = Sheets.Spreadsheets.Values.get(spreadSheetId, dataRange);
  var values = range.values;

  return values;
}

1 Answers

In your situation, how about the following modification?

From:

var values = range.values;

To:

var srcValues = range.values;
var temp = srcValues[0].map((_, c) => srcValues.map(r => r[c])).filter((_, c) => ![2, 3].includes(c + 1));
var values = temp[0].map((_, c) => temp.map(r => r[c]));
  • In this modification, at first, the value of range.values is transposed and remove the columns "B" and "C", and then, the values are transposed. By this, the values except for the columns "B" and "C" can be retrieved.

References:

Related