using json-2-csv package for the csv export now since the old package has not been updated in 4 years

This commit is contained in:
csawatzky 2025-02-28 14:50:36 -06:00
parent eb5fd127e3
commit cf559d48a2
4 changed files with 64 additions and 23 deletions

View file

@ -1,8 +1,7 @@
// import * as save from "save-svg-as-png";
// import * as jsonexport from "jsonexport";
import { or } from "./types";
// const jsonexport = require("jsonexport");
// const save = require("save-svg-as-png")
import { json2csv } from 'json-2-csv';
export function saveSVG(element: string, filename: string, options: Object) {
// save.saveSvgAsPng(document.getElementById(element), filename, options);
@ -52,25 +51,25 @@ export function exportDataToCSV(filename: string, data: Array<any>) {
return;
}
// jsonexport(data, function(err: any, csv: any) {
// if (err) return console.log(err);
// var blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
// var link = document.createElement("a");
// link.href = window.URL.createObjectURL(blob);
// link.download = or(filename, "generated") + ".csv";
// document.body.appendChild(link);
// link.click();
// setTimeout(function() {
// document.body.removeChild(link);
// window.URL.revokeObjectURL(link.href);
// }, 100);
// });
let csv = json2csv(data)
//console.log(csv)
var blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
var link = document.createElement("a");
link.href = window.URL.createObjectURL(blob);
link.download = or(filename, "generated") + ".csv";
document.body.appendChild(link);
link.click();
setTimeout(function() {
document.body.removeChild(link);
window.URL.revokeObjectURL(link.href);
}, 100);
}
export function exportJSON(filename: string, data: Array<any>) {
if (!data || !data.length) {
return;
}
//deprecated function
// export function exportJSON(filename: string, data: Array<any>) {
// if (!data || !data.length) {
// return;
// }
// jsonexport(data, function(err: any, csv: any) {
// if (err) return console.log(err);
@ -85,4 +84,4 @@ export function exportJSON(filename: string, data: Array<any>) {
// window.URL.revokeObjectURL(link.href);
// }, 100);
// });
}
//}