How to read an excel file from the server - placed in the same place as the html and js files?
I can download xlsx file with input. But I need to download the file automatically then page load. I can't download the file directly from the server.
let input = document.getElementById('input');
let table = document.getElementById('tbl-data');
let htmlEnd = ``;
input.addEventListener('change', function () {
readXlsxFile().then(function (data) {
tableGeneratorHead(data[0]);
htmlEnd += `<tbody> `;
for (let i = 1; i < data.length; i++) {
tableGenerator(data[i], i);
console.log('1');
}
htmlEnd += ` </tbody>`;
table.insertAdjacentHTML('beforeend', htmlEnd);
});
});
const tableGeneratorHead = function (val1, val2) {
htmlEnd += `<thead class="headTable"><tr> `;
val1.forEach(function (val) {
htmlEnd += `<th>${val} </th>`;
});
htmlEnd += `</tr></thead>`;
console.log(htmlEnd);
};
const tableGenerator = function (val1, val2) {
htmlEnd += `<tr> `;
if (val2 % 2 == 0) {
val1.forEach(function (val) {
htmlEnd += `<td class="one">${val} </td>`;
});
}
if (val2 % 2 > 0) {
val1.forEach(function (val) {
htmlEnd += `<td class="two">${val} </td>`;
});
}
htmlEnd += `</tr>`;
console.log(htmlEnd);
};
I tried to find an answer on the Internet but couldn't find anything I could use.