Spaces:
Running
Running
File size: 1,454 Bytes
8058d85 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
class ExcelViewer {
constructor(containerId) {
this.container = document.getElementById(containerId);
this.init();
}
init() {
// Create a table structure that mimics Excel
this.table = document.createElement('table');
this.table.className = 'excel-table';
this.container.appendChild(this.table);
}
loadData(data) {
// Clear existing data
this.table.innerHTML = '';
// Create header row
const headerRow = document.createElement('tr');
Object.keys(data[0]).forEach(key => {
const th = document.createElement('th');
th.textContent = key;
headerRow.appendChild(th);
});
this.table.appendChild(headerRow);
// Create data rows
data.forEach(item => {
const row = document.createElement('tr');
Object.values(item).forEach(value => {
const td = document.createElement('td');
td.textContent = value;
row.appendChild(td);
});
this.table.appendChild(row);
});
}
exportToExcel() {
// Implementation for exporting to Excel
// Would use SheetJS library
}
}
// Export for use in other files
if (typeof module !== 'undefined' && module.exports) {
module.exports = ExcelViewer;
} else {
window.ExcelViewer = ExcelViewer;
} |