简体   繁体   中英

How can I download CSV data from variable to a csv file?

I am using papa parse library. It helped me in converting JSON to CSV but how can I download the same data into a excel file. My data is huge

If I'm understanding your question correctly, you have a CSV file which you now want to tell the browser to download? Have you looked at https://github.com/eligrey/FileSaver.js/ ? Allows you to tell the browser to download a wide variety of files.

An example in using it:

var blob = new Blob(myBigCSVFile, {type: "text/csv;charset=utf-8"});
saveAs(blob, "file.csv");

The browser, upon reaching the saveAs function will download the file you specified.

Checkout SheetJS/js-xlsx library.

Supported read formats: Excel 2007+ XML Formats (XLSX/XLSM), Excel 2007+ Binary Format (XLSB), Excel 2003-2004 XML Format (XML "SpreadsheetML"), Excel 97-2004 (XLS BIFF8), Excel 5.0/95 (XLS BIFF5), OpenDocument Spreadsheet (ODS)

Supported write formats: XLSX, CSV (and general DSV), JSON and JS objects (various styles)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM