2

I have an issue that I am trying to resolve with the exported Date formats. My Google sheet has date format as MM/DD/YYYY and the CSV files have date format { Thu Aug 27 2020 00:00:00 GMT-0400 (Eastern Daylight Time) }

Looking to see if there is a way to get this CSV download code to use a date format or MM/DD/YYY.

Snip of code+++++++++++++++++++

function convertRangeToCsvFile_(csvFileName, sheet) {
  // get available data range in the spreadsheet
  var activeRange = sheet.getDataRange();
  try {
    var data = activeRange.getValues();
    var csvFile = undefined;

    // loop through the data in the range and build a string with the csv data
    if (data.length > 1) {
      var csv = "";
      for (var row = 0; row < data.length; row++) {
        for (var col = 0; col < data[row].length; col++) {
          if (data[row][col].toString().indexOf(",") != -1) {
            data[row][col] = "\"" + data[row][col] + "\"";
          }
        }

        // join each row's columns
        // add a carriage return to end of each row, except for the last one
        if (row < data.length-1) {
          csv += data[row].join(",") + "\r\n";
        }
        else {
          csv += data[row];
        }
      }
      csvFile = csv;
    }
    return csvFile;
  }
  catch(err) {
    Logger.log(err);
    Browser.msgBox(err);
  }
}
Tanaike
  • 181,128
  • 11
  • 97
  • 165
pbardell
  • 21
  • 2
  • 1
    I think that in your case, to use `getDisplayValues()` instead of `getValues()` might lead to the solution of your issue. [Ref](https://developers.google.com/apps-script/reference/spreadsheet/range#getDisplayValues()) How about this? The related threads are https://stackoverflow.com/q/23472440 https://stackoverflow.com/q/42383165 – Tanaike Aug 28 '20 at 01:47

0 Answers0