rainabba / jquery-table2excel

jQuery Plugin to export HTML tabled to Excel Spreadsheet Compatible Files
593 stars 666 forks source link

No border in excel file #76

Open kingzez opened 7 years ago

kingzez commented 7 years ago

the export excel file's content has no border

atalayxx commented 6 years ago

Okey! Search; console.log(tempRows);

Add before tempRows = $(o).html();

border and other style items are working!

Enjoy

vegetas940 commented 2 years ago
$(p).find("td,th").not(e.settings.exclude).each(function (i,q) {
    additionalStyles = "";
    if(e.settings.preserveColors){
        compStyle = getComputedStyle(q);
        additionalStyles += (compStyle && compStyle.backgroundColor ? "background-color: " + compStyle.backgroundColor + ";" : "");
        additionalStyles += (compStyle && compStyle.color ? "color: " + compStyle.color + ";" : "");
        //I added this line below, and it shows border in Excel. 1px border in Excel is too thick so I replaced it with 0.3pt.
        additionalStyles+=(compStyle&&compStyle.border?"border: "+compStyle.border.replace("1px",".3pt")+";":"");  
    }
    var rc = {
        rows: $(this).attr("rowspan"),
        cols: $(this).attr("colspan"),
        flag: $(q).find(e.settings.exclude)
    };
    if( rc.flag.length > 0 ) {
        tempRows += "<td> </td>";
    } else {
        tempRows += "<td";
        if( rc.rows > 0) {
            tempRows += " rowspan='" + rc.rows + "' ";
        }
        if( rc.cols > 0) {
            tempRows += " colspan='" + rc.cols + "' ";
        }
        if(additionalStyles){
            tempRows += " style='" + additionalStyles + "'";
        }
        tempRows += ">" + $(q).html() + "</td>";
    }
});