/*
* jQuery table2excel - v1.1.2
* jQuery plugin to export an .xls file in browser from an HTML table
* https://github.com/rainabba/jquery-table2excel
*
* Made by rainabba
* Under MIT License
*/
//table2excel.js
(function ( $, window, document, undefined ) {
var pluginName = "table2excel",
defaults = {
exclude: ".noExl",
name: "Table2Excel",
filename: "table2excel",
fileext: ".xls",
exclude_img: true,
exclude_links: true,
exclude_inputs: true,
preserveColors: false
};
// The actual plugin constructor
function Plugin ( element, options ) {
this.element = element;
// jQuery has an extend method which merges the contents of two or
// more objects, storing the result in the first object. The first object
// is generally empty as we don't want to alter the default options for
// future instances of the plugin
//
this.settings = $.extend( {}, defaults, options );
this._defaults = defaults;
this._name = pluginName;
this.init();
}
Plugin.prototype = {
init: function () {
var e = this;
var utf8Heading = "";
e.template = {
head: "" + utf8Heading + "
",
table: {
head: "
",
tail: "
"
},
foot: ""
};
e.tableRows = [];
// Styling variables
var additionalStyles = "";
var compStyle = null;
// get contents of table except for exclude
$(e.element).each( function(i,o) {
var tempRows = "";
$(o).find("tr").not(e.settings.exclude).each(function (i,p) {
// Reset for this row
additionalStyles = "";
// Preserve background and text colors on the row
if(e.settings.preserveColors){
compStyle = getComputedStyle(p);
additionalStyles += (compStyle && compStyle.backgroundColor ? "background-color: " + compStyle.backgroundColor + ";" : "");
additionalStyles += (compStyle && compStyle.color ? "color: " + compStyle.color + ";" : "");
}
// Create HTML for Row
tempRows += "
";
// Loop through each TH and TD
$(p).find("td,th").not(e.settings.exclude).each(function (i,q) { // p did not exist, I corrected
// Reset for this column
additionalStyles = "";
// Preserve background and text colors on the row
if(e.settings.preserveColors){
compStyle = getComputedStyle(q);
additionalStyles += (compStyle && compStyle.backgroundColor ? "background-color: " + compStyle.backgroundColor + ";" : "");
additionalStyles += (compStyle && compStyle.color ? "color: " + compStyle.color + ";" : "");
}
var rc = {
rows: $(this).attr("rowspan"),
cols: $(this).attr("colspan"),
align:$(this).attr("align"),
flag: $(q).find(e.settings.exclude)
};
var align='',color='';
if( rc.align && rc.align.length > 1 ) {
align =' align="'+rc.align+'" valign="center" ';
}
if( rc.flag.length > 0 ) {
tempRows += "