通过浏览器保存对话框下载客户端生成的CSV

时间:2017-11-27 23:55:44

标签: javascript html csv download export-to-csv

所以从技术上讲,我想使用json2csv库生成一个csv,并在生成它时想要下载一个带有浏览器保存对话框的文件,如下所示:

var csv = json2csv({ data: tableData.data, fields: fields });
var data = new Blob([csv], { type: 'text/plain;charset=utf-8' });
// Next : I want to download a file using a browser file dialog (wherein) i could change the filename
// FileSaver.saveAs(data, 'filename.csv'); 
// with this (above) i could download the file however I want the dialog box to open 

基本上所需的输出就像从服务器下载的文件,浏览器打开一个保存文件对话框(名称,路径,扩展名等)

这只能通过客户端吗?

我尝试过的解决方案:Create a file in memory for user to download, not through server这也只是在不打开保存文件对话框的情况下下载文件

CSV库:www.mircozeiss.com/json2csv

FileSaver.js:https://github.com/eligrey/FileSaver.js

0 个答案:

没有答案