-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fddb850
commit 8be5cc8
Showing
5 changed files
with
36 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
import { CsvBuilder } from 'filefy'; | ||
|
||
export default function ExportCsv( | ||
columns, | ||
data, | ||
filename = 'data', | ||
delimiter = ',' | ||
) { | ||
import('filefy') | ||
.then(({ CsvBuilder }) => { | ||
const builder = new CsvBuilder(filename + '.csv'); | ||
builder | ||
.setDelimeter(delimiter) | ||
.setColumns(columns.map((col) => col.title)) | ||
.addRows(Array.from(data)) | ||
.exportFile(); | ||
}) | ||
.catch((err) => { | ||
console.error(`exporting csv : unable to import 'filefy' : ${err}`); | ||
}); | ||
try { | ||
const builder = new CsvBuilder(filename + '.csv'); | ||
builder | ||
.setDelimeter(delimiter) | ||
.setColumns(columns.map((col) => col.title)) | ||
.addRows(Array.from(data)) | ||
.exportFile(); | ||
} catch (err) { | ||
console.err(`err in ExportCsv : ${err}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
import 'jspdf-autotable'; | ||
|
||
export default function ExportPdf(columns, data, filename = 'data') { | ||
import('jspdf-autotable') | ||
.then(() => { | ||
const JSpdf = | ||
typeof window !== 'undefined' ? require('jspdf').jsPDF : null; | ||
if (JSpdf !== null) { | ||
const content = { | ||
startY: 50, | ||
head: [columns.map((col) => col.title)], | ||
body: data | ||
}; | ||
const unit = 'pt'; | ||
const size = 'A4'; | ||
const orientation = 'landscape'; | ||
const doc = new JSpdf(orientation, unit, size); | ||
doc.setFontSize(15); | ||
doc.text(filename, 40, 40); | ||
doc.autoTable(content); | ||
doc.save(filename + '.pdf'); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.error( | ||
`exporting pdf : unable to import 'jspdf-autotable' : ${err}` | ||
); | ||
}); | ||
try { | ||
const JSpdf = typeof window !== 'undefined' ? require('jspdf').jsPDF : null; | ||
if (JSpdf !== null) { | ||
const content = { | ||
startY: 50, | ||
head: [columns.map((col) => col.title)], | ||
body: data | ||
}; | ||
const unit = 'pt'; | ||
const size = 'A4'; | ||
const orientation = 'landscape'; | ||
const doc = new JSpdf(orientation, unit, size); | ||
doc.setFontSize(15); | ||
doc.text(filename, 40, 40); | ||
doc.autoTable(content); | ||
doc.save(filename + '.pdf'); | ||
} | ||
} catch (err) { | ||
console.error( | ||
`exporting pdf : unable to import 'jspdf-autotable' : ${err}` | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters