How to wrap text according to columns in excel sheet using javascript?

Hi,

I have implemented code for generating data in excel report but i am facing issue that exported data is not wrapping correctly.

I am generating excel report using below code. Is wrapping text possible through javascript?

please let me know if any other good libraries in javascript.

How to wrap data in excel sheet using javascript?

downloadCSV("testData.csv");

function convertArrayOfObjectsToCSV(args) {
  var result, ctr, keys, columnDelimiter, lineDelimiter, data;
  data = args.data || null;
  if (data == null || !data.length) {
    return null;
  }
  columnDelimiter = args.columnDelimiter || ',';
  lineDelimiter = args.lineDelimiter || '\n';
  keys = Object.keys(data[0]);
  result = '';
  result += keys.join(columnDelimiter);
  result += lineDelimiter;
  data.forEach(function(item) {
    ctr = 0;
    keys.forEach(function(key) {
      if (ctr > 0) result += columnDelimiter;
      result += "\"" + item[key] + "\"";
      ctr++;
    });
    result += lineDelimiter;
  });
  return result;
}
  function downloadCSV(args) {
  var data, filename, link;
  var testData = [  
                  {  
                     "Value":"23",
                     "Label":"Processor 1 of DHANUSHKA-RD"
                  },
                  {  
                     "Value":"5.5",
                     "Label":"Processor 1 of RANDIMA-S"
                  },
                  {  
                     "Value":"1.57587548638132",
                     "Label":"Processor 1 of DEV-22"
                  },
                  {  
                     "Value":"0.719101123595506",
                     "Label":"Processor 1 of ESIGNS-AB"
                  }
               ]
  var csv = this.convertArrayOfObjectsToCSV({
    data: testData
  });
  if (csv == null) return;
  filename = args.filename || 'export.csv';
  if (!csv.match(/^data:text\/csv/i)) {
    csv = 'data:application/vnd.ms-excel,' + csv;
  }
  data = encodeURI(csv);
  link = document.createElement('a');
  link.setAttribute('wrapText',1);
  link.setAttribute('href', data);
  link.setAttribute('download', filename);
  link.click();
}

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.