Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to hide HTML columns when exporting to Excel

Mathias Rangel Wulff edited this pageMar 14, 2017 ·4 revisions

How to hide HTML columns when exporting to Excel?

Source:StackOverflow.com

Question

I'm trying to export HTML table using header output in php. I'm using jquery to hide the columns by checkbox event. My jquery code to unhide and hide column is:

$('.col').css('display','table-cell');$('.col').css('display','none');

When I export my html table with hidden columns, the hidden columns still appears.I want to hide those columns while exporting to Excel.

Answer

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

To skip unnecessary columns you can use "skipdisplaynone" parameter (like in the example below) or list columns you need in the SELECT statement instead "*".

To skip unnecessary columns you can use "skipdisplaynone" parameter (like in the example below) or list columns you need in the SELECT statement instead "*".

alasql('SELECT * FROM HTML("#table", {headers:true, skipdisplaynone:true})');alasql('SELECT Name FROM HTML("#table", {headers:true})');

See the working example below with table, where column "Name" is hiddenin jsFiddle:

functionexportExcel(){alasql('SELECT * INTO XLSX("table.xlsx",{headers:true}) \                    FROM HTML("#table",{headers:true,skipdisplaynone:true})');}
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/alasql/0.3.7/alasql.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.9.2/xlsx.core.min.js"></script><buttononclick="exportExcel()">Export table to Excel</button><p>Source table</p><tableid="table"title="banner"border="1"align="center"><thead><tr><th>ID</th><thstyle="display:none">Name</th><th>Month</th><th>Savings</th></tr></thead><tbody><tr><td>101</td><tdstyle="display:none">Ramesh</td><td>January</td><td>$100</td></tr><tr><td>102</td><tdstyle="display:none">Ram</td><td>Feb</td><td>$200</td></tr><tr><td>103</td><tdstyle="display:none">Ramna</td><td>Mar</td><td>$300</td></tr></tbody></table>

© 2014-2026,Andrey Gershun &Mathias Rangel Wulff

Please help improve the documentation by opening a PR on thewiki repo

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp