switched csv export to excel export
This commit is contained in:
@@ -8,7 +8,7 @@ Vue.component('warehouse-e-shop-order', {
|
||||
<template v-slot:table-top-buttons>
|
||||
<button @click="createCSVExportAndMarkAsAccepted" type="button" class="btn btn-outline-success">
|
||||
<i class="fas fa-file-excel"></i>
|
||||
CSV Export für neue Bestellungen
|
||||
Excel Export für neue Bestellungen
|
||||
</button>
|
||||
</template>
|
||||
|
||||
@@ -48,16 +48,32 @@ Vue.component('warehouse-e-shop-order', {
|
||||
return;
|
||||
}
|
||||
|
||||
const blob = new Blob([response.data], {type: 'text/csv charset=utf-8;'});
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
await new Promise((resolve, reject) => {
|
||||
const script = document.createElement('script');
|
||||
script.src = '/plugins/xlsx/xlsx.min.js';
|
||||
script.onload = resolve;
|
||||
script.onerror = reject;
|
||||
document.head.appendChild(script);
|
||||
})
|
||||
|
||||
const link = document.createElement("a");
|
||||
link.setAttribute("href", url);
|
||||
link.setAttribute("download", "Export.csv");
|
||||
document.body.appendChild(link); // Required for FF
|
||||
const wb = this.window.XLSX.utils.book_new();
|
||||
|
||||
link.click(); // This will download the data file named "my_data.csv".
|
||||
link.remove();
|
||||
const ws = this.window.XLSX.utils.json_to_sheet(response.data);
|
||||
|
||||
for (const cell in ws) {
|
||||
if (cell.startsWith('!')) continue; // Skip non-cell properties like '!ref'
|
||||
const cellValue = ws[cell].v;
|
||||
if (cellValue?.toString().includes('\n')) {
|
||||
// console.log('Found newline in cell:', cell, cellValue);
|
||||
if (!ws[cell].s) ws[cell].s = {};
|
||||
ws[cell].s.alignment = {wrapText: true, vertical: 'center'};
|
||||
} else {
|
||||
ws[cell].s = {alignment: {vertical: 'center'}};
|
||||
}
|
||||
}
|
||||
|
||||
this.window.XLSX.utils.book_append_sheet(wb, ws, "Export");
|
||||
this.window.XLSX.writeFile(wb, 'Export.xlsx');
|
||||
|
||||
await this.$refs.table.$refs.table.fetchData();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user