I working on export html table to excel using JAVASCRIPT . I face issue it not export to excel office New version with extension xlsx
.
but it working fine and export to old version office excel with extension xls
.
when export from html table to excel new version with xlsx
extension it give me error
cannot open file `.xlsx` because file extension is not valid or file corrupted .
so How to solve this issue to working with xlsx
extension and open new version excel .
`function getselected_civilid() {
debugger
var selectedCivilIds = [];
$("input[name='statusCheckbox']:checked").each(function () {
selectedCivilIds.push($(this).val());
});
if (selectedCivilIds.length > 0) {
// Create an HTML table with headers
var table = "<table><tr><th>م</th><th>رقم السجل التجاري</th><th>رقم الترخيص</th><th>رقم الجهه المدني</th><th>الكيان القانوني</th><th>المحافظة</th><th>القطاع</th><th>كود النشاط الدولى</th><th>اسم المنشأة</th><th>العنوان</th><th>الرقم الالي للعنوان</th><th>المدينة</th><th>رقم التليفون</th><th>البريد الالكترونى</th></tr>";
$("input[name='statusCheckbox']:checked").each(function () {
var row = $(this).closest("tr"); // Get the parent row of the checkbox
var cells = row.find("td"); // Get all the cells in the row
table += "<tr>";
cells.each(function () {
table += "<td>" + $(this).text() + "</td>"; // Add each cell value to the table
});
table += "</tr>";
});
table += "</table>";
var blob = new Blob([table], {
type: "application/vnd.ms-excel;charset=utf-8"
});
var link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "LastData.xls"; // Set the filename for the downloaded file
link.click();
}
}`
when debug var table
it give me html table script as fiddle below so How to export to excel xlsx
New version
https://jsfiddle.net/36s1qhov/