36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
// Reads employee names from first column of xlsx (skips header row 0)
|
|
export function readEmployeeNames(arrayBuffer) {
|
|
const wb = XLSX.read(arrayBuffer, { type: 'array' });
|
|
const sheet = wb.Sheets[wb.SheetNames[0]];
|
|
const rows = XLSX.utils.sheet_to_json(sheet, { header: 1 });
|
|
return rows.slice(1)
|
|
.map(row => String(row[0] ?? '').trim())
|
|
.filter(name => name.length > 0);
|
|
}
|
|
|
|
// Exports schedule as xlsx blob
|
|
// assignments: [{ date: "2026-04-01", employeeId }]
|
|
// employees: [{ id, name }]
|
|
export function exportSchedule(assignments, employees) {
|
|
const nameById = Object.fromEntries(employees.map(e => [e.id, e.name]));
|
|
const names = assignments.map(a => nameById[a.employeeId] ?? '');
|
|
const dates = assignments.map(a => {
|
|
const [y, m, d] = a.date.split('-');
|
|
return d + '.' + m + '.' + y;
|
|
});
|
|
const ws = XLSX.utils.aoa_to_sheet([names, dates]);
|
|
const wb = XLSX.utils.book_new();
|
|
XLSX.utils.book_append_sheet(wb, ws, 'Moderationsplan');
|
|
const buf = XLSX.write(wb, { type: 'array', bookType: 'xlsx' });
|
|
return new Blob([buf], { type: 'application/octet-stream' });
|
|
}
|
|
|
|
export function downloadBlob(blob, filename) {
|
|
const url = URL.createObjectURL(blob);
|
|
const a = document.createElement('a');
|
|
a.href = url;
|
|
a.download = filename;
|
|
a.click();
|
|
URL.revokeObjectURL(url);
|
|
}
|