3

I have used the JavaScript function from this question and tried to adapt it to my app. It works but it also could be improved and I hope, you will help me to do it

This is the function

function exportExcelReport(tblId) {
    var tab_text = "<table border='2px'><tr>";
    var table = document.getElementById(tblId);

    var style;
    for (var j = 0; j < table.rows.length; j++) {
        style = table.rows[j].className.split(" ");
        if (style.length < 2)
        tab_text = tab_text + table.rows[j].innerHTML + "</tr>";
    }

    tab_text = tab_text + "</table>";
    tab_text = tab_text.replace(/<a[^>]*>|<\/a>/g, "");
    tab_text = tab_text.replace(/<img[^>]*>/gi, "");
    tab_text = tab_text.replace(/<input[^>]*>|<\/input>/gi, "");

    return window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));
}

This is how the table looks like Table html

This is what I get as a result after export enter image description here

As you can see, the exported excel file does not have a grid in the backround what actually looks strange. Do you have any idea, why is this happening?

Also I would like to remove the last column, that one after YTD. Is it somehow possible to adjust tab_text.replace(...) in the code abowe, so it that it could be ignored while exporting.

The column looks like this in html

</td><td width='20px'>
    <a class='infobox' href=''> 
         <img src='img/info.jpg' alt='info' width='18' height='18'>
         <span> 
             Service Engineer: ... <br>
             Datasource: ...
         </span>
    </a>
</tr>

Thx in advance!

Community
  • 1
  • 1
amsalk
  • 577
  • 1
  • 5
  • 23

1 Answers1

0

yes we can do this by Jquery.

Example:

http://www.jqueryscript.net/demo/Export-Html-Table-To-Excel-Spreadsheet-using-jQuery-table2excel/

ItzMe_Ezhil
  • 1,276
  • 2
  • 11
  • 22
  • 1
    Please don't post links as an answer. In future, this answer might be irrelevant if the link gets modified. Post the code relevant to solving OP's problem from the link. And include link as a reference. – Prerak Sola Jun 24 '15 at 11:59
  • I have already tried to implement this feature with table2excel lib but it did not work for me. I have written about it in one of my previous [questions](http://stackoverflow.com/questions/30189310/table2excel-plugin-does-not-work). – amsalk Jun 24 '15 at 12:16