<!DOCTYPE html>
<
html
>
<
head
>
<
title
>jQuery table2excel plugin</
title
>
<
script
src
=
</
script
>
<
script
src
=
"jquery.table2excel.js"
></
script
>
</
head
>
<
body
>
<
h1
style
=
"color:green"
>GeeksForGeeks</
h1
>
<
b
>jQuery table2excel plugin </
b
>
<
p
></
p
>
<
table
class
=
"table2excel"
>
<
thead
>
<
tr
class
=
"noExl"
>
<
td
>
Table 1 Header, column 1 (not exported)</
td
>
<
td
>Table 1 Header, column 2(not exported)
</
td
>
</
tr
>
<
tr
><
td
>Table 1 Header, column 1 (exported)</
td
>
<
td
>Table 1 Header, column 2 (exported)</
td
></
tr
>
</
thead
>
<
tbody
>
<
tr
><
td
>Row 1, column 1 data of table1</
td
>
<
td
>Row 1 column 2 data of table 1</
td
></
tr
>
<
tr
><
td
>Row 2, column 1 data of table1</
td
>
<
td
>Row 2, column 2 dataof table1</
td
></
tr
>
</
tbody
>
<
tfoot
>
<
tr
><
td
colspan
=
"2"
>This is the footer of table 1.</
td
></
tr
>
</
tfoot
>
</
table
>
<
button
class
=
"exportBtnClass"
>Export to XLS file</
button
><
p
></
p
>
<
table
class
=
"table2excel colorClass"
>
<
thead
>
<
tr
class
=
"noExl"
>
<
td
>Table 2 Header, column 1 (not exported)</
td
>
<
td
>Table 2 Header, column 1 (not exported)</
td
></
tr
>
<
tr
><
td
style
=
"background-color: green;"
>
Table 2 Header, column 1 (exported with colors)</
td
>
<
td
>Table 2 Header, column 2 (exported)</
td
></
tr
>
</
thead
>
<
tbody
>
<
tr
><
td
style
=
"background-color: red;"
>
Row 1, column 1 data of table2</
td
>
<
td
>Row 1 column 2 data of table2</
td
></
tr
>
<
tr
><
td
>Row 2, column 1 data of table2</
td
>
<
td
>Row 2, column 2 data of table2</
td
></
tr
>
</
tbody
>
<
tfoot
>
<
tr
><
td
colspan
=
"2"
>
This is the footer of table 2</
td
></
tr
>
</
tfoot
>
</
table
>
<
button
class
=
"exportBtnClass"
>
Export to XLS file
</
button
>
<
script
>
$(function() {
$(".exportBtnClass").click(function(e){
var table = $(this).prev('.table2excel');
if(table && table.length){
var preserveColors =
(table.hasClass('colorClass') ? true : false);
$(table).table2excel({
// This class's content is excluded from getting exported
exclude: ".noExl",
name: "Output excel file ",
filename:
"outputFile-" + new Date().toString().replace(/[\-\:\.]/g, "") + ".xls",
fileext: ".xls", //File extension type
exclude_img: true,
exclude_links: true,
exclude_inputs: true,
preserveColors: preserveColors
});
}
});
});
</
script
>
</
body
>
</
html
>