|
|
@@ -34,12 +34,18 @@ export default {
|
|
|
throw new Error('filename cannot be empty');
|
|
|
}
|
|
|
filename = filename.replace(/.xlsx$/i, '');
|
|
|
- const columns = ref.columns.filter(i => !!i.property);
|
|
|
+ const columns = ref.columns.filter(column => !!column.property);
|
|
|
let workbook = XLSX.utils.book_new();
|
|
|
let sheet = XLSX.utils.aoa_to_sheet([
|
|
|
- columns.map(c => c.label),
|
|
|
- ...ref.tableData.map(i => {
|
|
|
- return columns.map(c => getPropByPath(i, c.property).v);
|
|
|
+ columns.map(column => column.label),
|
|
|
+ ...ref.tableData.map(row => {
|
|
|
+ return columns.map((column, index) => {
|
|
|
+ const value = getPropByPath(row, column.property).v;
|
|
|
+ if (column.formatter) {
|
|
|
+ return column.formatter(row, column, value, index);
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ });
|
|
|
})
|
|
|
]);
|
|
|
XLSX.utils.book_append_sheet(workbook, sheet, filename);
|