Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

export 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 :: clean code javascript 
Javascript :: angular custom directive 
Javascript :: how custom angular material component date format 
Javascript :: javascript for in 
Javascript :: document.getanimation 
Javascript :: javascript double question mark 
Javascript :: d3 v6 
Javascript :: Toasting a message 
Javascript :: javascript floating point addition 
Javascript :: string comparison javascript 
Javascript :: remove duplicate array 
Javascript :: jsx return greatest number between two numbers 
Javascript :: node fetch 
Javascript :: switch javascript 
Javascript :: js add zeros before number 
Javascript :: jquery select element with class 
Javascript :: create a react app 
Javascript :: jquery get name value method 
Javascript :: convert array to object with custom keys 
Javascript :: map in js 
Javascript :: create table using jade 
Javascript :: get numbers from a string 
Javascript :: NodeJS router model 
Javascript :: google scripts urlfetchapp hearders and body 
Javascript :: Fill rect in jspdf 
Javascript :: change base js 
Javascript :: filter in javascipt 
Javascript :: selialize jquery 
Javascript :: js intellisence not working 
Javascript :: How to submit form with enter press in html textarea 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =