mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-04 04:22:58 +00:00
xlsx test
This commit is contained in:
+32
-37
@@ -5,6 +5,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Admin Dashboard - PP Kunovice</title>
|
<title>Admin Dashboard - PP Kunovice</title>
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||||
|
<script src="https://cdn.sheetjs.com/xlsx/0.18.5/package/dist/xlsx.full.min.js"></script>
|
||||||
<script src="https://cdn.tailwindcss.com"></script>
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
<style>
|
<style>
|
||||||
:root {
|
:root {
|
||||||
@@ -4382,7 +4383,7 @@ function filterReservations() {
|
|||||||
displayReservations(filtered);
|
displayReservations(filtered);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to export reservations to CSV with proper column separation
|
// Function to export reservations to XLSX
|
||||||
function exportReservations() {
|
function exportReservations() {
|
||||||
if (!window.allReservations || !window.allReservations.length) {
|
if (!window.allReservations || !window.allReservations.length) {
|
||||||
showNotification('Žádné rezervace k exportu', 'warning');
|
showNotification('Žádné rezervace k exportu', 'warning');
|
||||||
@@ -4437,47 +4438,41 @@ function exportReservations() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create CSV content with semicolon delimiter
|
// Prepare data for XLSX
|
||||||
const headers = ['Řidič', 'Vozidlo', 'Od', 'Do', 'Účel'];
|
const headers = ['Řidič', 'Vozidlo', 'Od', 'Do', 'Účel'];
|
||||||
|
|
||||||
// Create CSV rows
|
// Convert data to worksheet
|
||||||
const csvRows = [];
|
const wsData = [
|
||||||
|
headers,
|
||||||
// Add header row
|
...dataToExport.map(res => [
|
||||||
csvRows.push(headers.join(';'));
|
res.driverName || '',
|
||||||
|
res.vehicle || '',
|
||||||
// Add data rows
|
formatDateTime(res.start) || '',
|
||||||
for (const res of dataToExport) {
|
formatDateTime(res.end) || '',
|
||||||
const row = [
|
res.purpose || ''
|
||||||
`"${String(res.driverName || '').replace(/"/g, '""')}"`,
|
])
|
||||||
`"${String(res.vehicle || '').replace(/"/g, '""')}"`,
|
];
|
||||||
`"${formatDateTime(res.start) || ''}"`,
|
|
||||||
`"${formatDateTime(res.end) || ''}"`,
|
|
||||||
`"${String(res.purpose || '').replace(/"/g, '""')}"`
|
|
||||||
];
|
|
||||||
csvRows.push(row.join(';'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create CSV string with BOM for Excel
|
// Create worksheet
|
||||||
const csvString = '\uFEFF' + csvRows.join('\r\n');
|
const ws = XLSX.utils.aoa_to_sheet(wsData);
|
||||||
|
|
||||||
// Create and trigger download
|
// Set column widths
|
||||||
const blob = new Blob([csvString], { type: 'text/csv;charset=utf-8' });
|
const colWidths = [
|
||||||
const link = document.createElement('a');
|
{ wch: 20 }, // Řidič
|
||||||
|
{ wch: 25 }, // Vozidlo
|
||||||
|
{ wch: 20 }, // Od
|
||||||
|
{ wch: 20 }, // Do
|
||||||
|
{ wch: 40 } // Účel
|
||||||
|
];
|
||||||
|
ws['!cols'] = colWidths;
|
||||||
|
|
||||||
|
// Create workbook
|
||||||
|
const wb = XLSX.utils.book_new();
|
||||||
|
XLSX.utils.book_append_sheet(wb, ws, 'Rezervace');
|
||||||
|
|
||||||
|
// Generate XLSX file
|
||||||
const timestamp = new Date().toISOString().split('T')[0];
|
const timestamp = new Date().toISOString().split('T')[0];
|
||||||
|
XLSX.writeFile(wb, `rezervace_${timestamp}.xlsx`);
|
||||||
link.href = URL.createObjectURL(blob);
|
|
||||||
link.download = `rezervace_${timestamp}.csv`;
|
|
||||||
link.style.display = 'none';
|
|
||||||
|
|
||||||
document.body.appendChild(link);
|
|
||||||
link.click();
|
|
||||||
|
|
||||||
// Clean up
|
|
||||||
setTimeout(() => {
|
|
||||||
document.body.removeChild(link);
|
|
||||||
URL.revokeObjectURL(link.href);
|
|
||||||
}, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to format date and time
|
// Helper function to format date and time
|
||||||
|
|||||||
Reference in New Issue
Block a user