59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
(function () {
|
|
function isFilled(cell) {
|
|
return cell !== null && cell !== undefined && String(cell).trim() !== "";
|
|
}
|
|
|
|
function escapeText(value) {
|
|
return String(value ?? "")
|
|
.replace(/&/g, "&")
|
|
.replace(/</g, "<")
|
|
.replace(/>/g, ">")
|
|
.replace(/"/g, """)
|
|
.replace(/'/g, "'");
|
|
}
|
|
|
|
window.WorkbenchExcelPreview = {
|
|
filledRows(rows) {
|
|
return rows.filter(row => Array.isArray(row) && row.some(isFilled));
|
|
},
|
|
|
|
render(containerId, headers, rows) {
|
|
const container = document.getElementById(containerId);
|
|
if (!container) return;
|
|
|
|
if (!rows || rows.length === 0) {
|
|
container.innerHTML = '<div class="empty-preview">Keine Excel-Daten geladen.</div>';
|
|
return;
|
|
}
|
|
|
|
const headerHtml = headers
|
|
.map(header => `<th>${escapeText(header)}</th>`)
|
|
.join("");
|
|
|
|
const bodyHtml = rows
|
|
.map(row => `<tr>${headers.map((_, index) => `<td>${escapeText(row[index])}</td>`).join("")}</tr>`)
|
|
.join("");
|
|
|
|
container.innerHTML = `
|
|
<div class="excel-preview-scroll">
|
|
<table class="excel-preview-table">
|
|
<thead><tr>${headerHtml}</tr></thead>
|
|
<tbody>${bodyHtml}</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="preview-count">${rows.length} Zeilen geladen</div>
|
|
`;
|
|
},
|
|
|
|
rowsToObjects(headers, rows) {
|
|
return rows.map(row => {
|
|
const obj = {};
|
|
headers.forEach((header, index) => {
|
|
obj[header] = row[index] || "";
|
|
});
|
|
return obj;
|
|
});
|
|
}
|
|
};
|
|
})();
|