Skip to content

How to export HTML table to Excel

Mathias Rangel Wulff edited this page Jun 13, 2015 · 4 revisions

How to export HTML table to Excel?

Answer

You can export table from HTML to Excel and skip some columns with AlaSQL and js-xlsx libraries.

See the working example below or in jsFiddle:

    function exportExcel() {
        alasql('SELECT * INTO XLSX("myinquires.xlsx",{headers:true}) \
                    FROM HTML("#MyInquires",{headers:true})');
    }
    <script src="http://alasql.org/console/alasql.min.js"></script>
    <script src="http://alasql.org/console/xlsx.core.min.js"></script>
    <button onclick="exportExcel()">Export table to Excel</button>
    <p>Source table</p>
    <table id="MyInquires">
    	<thead><tr><th>#<th>Inquiry<th>Topic</thead>
    	<tbody>
    		<tr><td>1<td>WinPhone<td>Screen
    		<tr><td>2<td>iPhone<td>Keyboard
    		<tr><td>3<td>Android<td>Memory
    	</tbody>
    </table>
Clone this wiki locally