Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

export to csv - Javascript - Download CSV as File

function downloadFile(fileName, urlData) {

    var aLink = document.createElement('a');
    var evt = document.createEvent("HTMLEvents");
    evt.initEvent("click");
    aLink.download = fileName;
    aLink.href = urlData;
    aLink.dispatchEvent(evt);
}

var data = '"Column One","Column Two","Column Three"';
downloadFile('2.csv', 'data:text/csv;charset=UTF-8,' + encodeURIComponent(data));
Comment

export csv single javascript

//EXPORT SINGLE COLUMN CSV JAVASCRIPT
function downloadCSV(csv, filename) {
var csvFile;
var downloadLink;
csvFile = new Blob([csv], {type: "text/csv"});
downloadLink = document.createElement("a");
downloadLink.download = filename;
downloadLink.href = window.URL.createObjectURL(csvFile);
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
}
//export
function exportss(filename) {
var csv = [];
var rows = document.querySelectorAll("table tr");
let aa = Array.from(rows).map((x,y)=> {
var row = [], cols = rows[y].querySelectorAll("td, th"); 
    Array.from(cols).forEach((a,b)=>{
        row.push(cols[b].innerText);
    })
    csv.push(row.join(","))
    console.log(csv)   
    return x
    })
downloadCSV(csv.join("
"), filename);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: index and id together angularjs 
Javascript :: jquery how to get element insde div 
Javascript :: json schema beispiel 
Javascript :: mdi/js icons with vue 
Javascript :: change css file with js 
Javascript :: slideshow react npm 
Javascript :: destructuring object 
Javascript :: mongoose encrypt database using mongoose encrypt package 
Javascript :: mongoose encrypt database using mongoose encryption package 
Javascript :: leaflet flyto 
Javascript :: react linking to documents 
Javascript :: remove unused css and js wordpress 
Javascript :: remove array value by index js 
Javascript :: vue slice words 
Javascript :: get buildspec.yml file for react app 
Javascript :: jQuery download video from URL 
Javascript :: get date in format 
Javascript :: javascript create object from key value pairs 
Javascript :: react native elements bottom sheet 
Javascript :: Assume that x is a char variable has been declared and already given a value. Write an expression whose value is true if and only if x is a upper-case letter. 
Javascript :: js not not 
Javascript :: hover on child from parent mui react 
Javascript :: nodejs mysql error handling with user example 
Javascript :: js add props to obj conditionally 
Javascript :: shopify api for add to cart 
Javascript :: js spread operator component example 
Javascript :: promises in es6 
Javascript :: Variadic function in javascript 
Javascript :: java script append element to array 
Javascript :: componentwillreceiveprops for functional component 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =