I am working on vueJs template and I need to export data of tables in three formats which are .pdf, .csv, .xls I tried with this question but its show Utils undefined. so how can I achieve what I want ?
Asked
Active
Viewed 2.1k times
1 Answers
9
Easy way
If you can use different table component try to look into Vue materialize datatable
It's letting you to export in XLS and print to PDF
Without any component
The way I personally use If i need to export any JSON that is consist of more fields than there are in the actual table:
import Papa from "papaparse";
var blob = new Blob([Papa.unparse(jsonData)], { type: 'text/csv;charset=utf-8;' });
var link = document.createElement("a");
var url = URL.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", 'filename.csv');
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
So, we actually unparsing JSON data into the blob, creating dynamic element which linked to it and downloading the file.

Justice47
- 682
- 6
- 16
-
Any recommendations on how to write a unit test for this? – Tom Nov 11 '20 at 23:23
-
@Tom sorry, hadn't written any unit tests for this – Justice47 Aug 31 '21 at 18:56