Home > OS >  How to Enclose an Entire Google Sheets .csv Column in Quotes?
How to Enclose an Entire Google Sheets .csv Column in Quotes?

Time:07-05

I'm currently trying to enclose an entire column in a Google Sheets CSV file in double quotes for a script that I'm writing. I've attached a link for the sample CSV sheet below:

enter image description here

UPDATED Ver:

I added a ternary operator which works if we'll be adding a single if-else like condition for arrow functions in javascript.

function myFunction() {
  var ss = SpreadsheetApp.getActiveSpreadsheet(); 
  var sheet = ss.getActiveSheet();
  var range = sheet.getRange(1,2,sheet.getLastRow(),1); 
  var values = range.getValues();
  var quoted = values.map(x => x.map(y => y[0] == '"' && y[y.toString.length] == '"' ? y : '"'   y   '"' ));
  range.setValues(quoted);
}
  • Related