Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

convert json / array to excel in javascript

//HTML
<button onclick="exportToCsv()">export to CSV</button>

// Javascript
var Results = [
  ["Col1", "Col2", "Col3", "Col4"],
  ["Data", 50, 100, 500],
  ["Data", -100, 20, 100],
];

exportToCsv = function() {
  var CsvString = "";
  Results.forEach(function(RowItem, RowIndex) {
    RowItem.forEach(function(ColItem, ColIndex) {
      CsvString += ColItem + ',';
    });
    CsvString += "
";
  });
  CsvString = "data:application/csv," + encodeURIComponent(CsvString);
 var x = document.createElement("A");
 x.setAttribute("href", CsvString );
 x.setAttribute("download","somedata.csv");
 document.body.appendChild(x);
 x.click();
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: sort in array in javascript 
Javascript :: use of this keyword in js 
Javascript :: input show validation message 
Javascript :: express-rate-limit nodejs 
Javascript :: javascript this 
Javascript :: form data display javascript 
Javascript :: d3 script 
Javascript :: address format json 
Javascript :: add two float numbers in javascript 
Javascript :: how to loop over an array in js 
Javascript :: autocomplete list angular 8 material 
Javascript :: how to make a discord bot send a message 
Javascript :: javascript fetch 
Javascript :: next js link 
Javascript :: for loop on array in javascript 
Javascript :: react native build 
Javascript :: nodejs sequelize find 
Javascript :: react social login buttons 
Javascript :: angular ngstyle variable 
Javascript :: .includes meaning in javascript 
Javascript :: how can i do metaname csrf token attrcontent in vanilla javascrip 
Javascript :: multiply js 
Javascript :: router nodejs 
Javascript :: nodejs class template export 
Javascript :: react router dom default params 
Javascript :: shopify bypass cart 
Javascript :: last index of array js 
Javascript :: numeros que mais se repetem em um array 
Javascript :: convert div to pdf javascript 
Javascript :: cy visit cypress 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =