0

this is the fiddle

https://jsfiddle.net/shaswatatripathy/ym4egje0/7/

How to use the tableToExcel function and make it work in Internet Explorer 11

Also It should work in Google chrome thats better . Cant use any Iframe

Objective Have to export table to excel file for IE and after much searching found this function from Generate excel sheet from html tables using jquery

but not able to use it .

HTML

<input id="btnExport" type="button" value = "Generate File" />
<table id="table">
<th>
  <tr>
    <td>coulmn1</td>
    <td>column2</td>
  </tr>
</th>
<tbody>
<tr>
  <td>row1column1</td>
  <td>row1column2</td>
</tr>
</tbody>
</table>

JS

$("#btnExport").click(function (e) { 

TableToExcel;

});
var TableToExcel = (function () {

    var uri = 'data:application/vnd.ms-excel;base64,'
    , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table cellspacing="0" rules="rows" border="1" style="color:Black;background-color:White;border-color:#CCCCCC;border-width:1px;border-style:None;width:100%;border-collapse:collapse;font-size:9pt;text-align:center;">{table}</table></body></html>'
    , base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
    , format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }
    return function (table, name) {
        if (!table.nodeType) table = document.getElementById(table)
        var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
        if (navigator.msSaveBlob) {
            var blob = new Blob([format(template, ctx)], { type: 'application/vnd.ms-excel', endings: 'native' });
            navigator.msSaveBlob(blob, 'export.xls')
        } else {
            window.location.href = uri + base64(format(template, ctx))
        }
    }
})()
shaswatatripathy
  • 161
  • 1
  • 5
  • 13
  • give us a clue, which part(s) of it aren't working now? People don't want to have to debug the entire thing. Presumably you've narrowed it down to some specific problems? Some lines which throw errors maybe, or cause unexpected behaviour? Can you confirm a browser it _does_ work in, or is the whole thing just buggy? – ADyson Jun 07 '17 at 10:47
  • updated the query . hope this helps – shaswatatripathy Jun 07 '17 at 10:51
  • not really. You haven't answered any of my questions. All you've done is repeat yourself and still say, in very vague terms, "it doesn't work". Please try and address the specific points I made above. – ADyson Jun 07 '17 at 10:54
  • not able to use the function , like how to use this kind of function and how to convert html table to Excel file in client side for exclusively Internet explorer – shaswatatripathy Jun 07 '17 at 10:55
  • yes, that's the 3rd time you've said that. Please try and answer my specific questions regarding your code. – ADyson Jun 07 '17 at 10:55
  • in very simple words I want to convert html table to xlsx file in IE . how to . help me . thats it – shaswatatripathy Jun 07 '17 at 10:56
  • if you can't answer my specific queries then sorry I can't help you. I'm not going to do your most basic tasks for you. You've got some code, you say it "doesn't work". You say you want it to work in IE11. So, I need to know 1) does it currently work in any other browsers? 2) where exactly does it fail? (i.e. if you get an error, then provide line number and error message) 3) If it doesn't fail, but it produces unexpected results, please describe what it produces, and what you believe it _should_ produce. I simply request some basic debugging effort and creation of a problem statement. – ADyson Jun 07 '17 at 11:11

0 Answers0