5

I am creating a web page where the data is uploaded to an HTML table. After some calculation, a output HTML table gets generated.The output HTML table must be dumped in Excel (.xlsx) format. I'm using SheetJS library for uploading and downloading purpose.

I have tried the following code which exports the data to excel without any formatting.

HTML Table code:- (Output HTML after calculation)

<table border="1" id="tempTable">
    <thead>
        <tr>
            <th style="border:1px solid #000000;border-collapse: collapse">Column1</th>
            <th style="border:1px solid #000000;border-collapse: collapse">Column2</th>
            <th style="border:1px solid #000000;border-collapse: collapse">Column3</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td style="border:1px solid #000000;border-collapse: collapse">R1C1</td>
            <td style="border:1px solid #000000;border-collapse: collapse">R1C2</td>
            <td style="border:1px solid #000000;border-collapse: collapse">R1C3</td>
        </tr>
        <tr>
            <td style="border:1px solid #000000;border-collapse: collapse">R2C1</td>
            <td style="border:1px solid #000000;border-collapse: collapse">R2C2</td>
            <td style="border:1px solid #000000;border-collapse: collapse">R2C3</td>
        </tr>
    </tbody>
</table>

JavaScript code:- (Function that helps me to export data)

function ExportAllData_HTML(){
        var wb = {SheetNames:[],Sheets:{}};
        var ws9 = XLSX.utils.table_to_sheet(document.getElementById('tempTable'),{raw:true});
        wb.SheetNames.push('Temp Table'); wb.Sheets["Temp Table"] = ws9;
        XLSX.writeFile(wb,"myTemp.xlsx",{cellStyles:true});
}

I've searched and found out that only Inline CSS works while exporting the data. But that too doesn't seem to be working.

I'm not able to export data to Excel with CSS that has been applied.

Is there any other way that I can export data with CSS that has been applied.

BBRK
  • 102
  • 1
  • 1
  • 12

1 Answers1

0

if you just need to export the html table you see , I think the following link do what you want : Javascript to export html table to Excel

Code.king
  • 37
  • 1
  • 4