Skip to content

devjanaprime/javascript_csv_example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Create CSV Example

A quick example of creating a CSV spreadsheet file from a string in javascript.

Send the following function a string to convert to CSV and a filename. The file will automatically be created and downloaded.

let downloadCsv = ( string, fileName ) => {  
    let data = encodeURI( 'data:text/csv;charset=utf-8,' + string );
    link = document.createElement( 'a' );
    link.setAttribute( 'href', data );
    link.setAttribute( 'download', fileName );
    link.click();
}

Note: The example uses four inputs, creates a row of them with commas between, then repeats that line.

About

Simple example of creating a CSV file to be downloaded in vanilla JS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors