Export html table data to Excel using JavaScript / JQuery is not working properly in chrome browser

export html table to excel using jquery example
export html table to excel javascript
export html table to excel with formatting javascript
export html table data to excel using jquery without plugin
export html table to excel using jquery plugin
export html div to excel using javascript
export html table to excel with css using jquery
export html table to xlsx using jquery

I have a HTML table in velocity template. I want to export the html table data to excel using either java script or jquery, comatibale with all browser. I am using below script

<script type="text/javascript">
function ExportToExcel(mytblId){
       var htmltable= document.getElementById('my-table-id');
       var html = htmltable.outerHTML;
       window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html));
    }
</script>

This script works fine in Mozilla Firefox,it pops-up with a dialog box of excel and ask for open or save options. But when I tested same script in Chrome browser it is not working as expected,when clicked on button there is no pop-up for excel. Data gets downloaded in a file with "file type : file" , no extension like .xls There are no errors in chrome console.

Jsfiddle example :

http://jsfiddle.net/insin/cmewv/

This works fine in mozilla but not in chrome.

Chrome browser Test Case :

First Image:I click on Export to excel button

and result :

Excel export script works on IE7+, Firefox and Chrome.

function fnExcelReport()
{
    var tab_text="<table border='2px'><tr bgcolor='#87AFC6'>";
    var textRange; var j=0;
    tab = document.getElementById('headerTable'); // id of table

    for(j = 0 ; j < tab.rows.length ; j++) 
    {     
        tab_text=tab_text+tab.rows[j].innerHTML+"</tr>";
        //tab_text=tab_text+"</tr>";
    }

    tab_text=tab_text+"</table>";
    tab_text= tab_text.replace(/<A[^>]*>|<\/A>/g, "");//remove if u want links in your table
    tab_text= tab_text.replace(/<img[^>]*>/gi,""); // remove if u want images in your table
    tab_text= tab_text.replace(/<input[^>]*>|<\/input>/gi, ""); // reomves input params

    var ua = window.navigator.userAgent;
    var msie = ua.indexOf("MSIE "); 

    if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))      // If Internet Explorer
    {
        txtArea1.document.open("txt/html","replace");
        txtArea1.document.write(tab_text);
        txtArea1.document.close();
        txtArea1.focus(); 
        sa=txtArea1.document.execCommand("SaveAs",true,"Say Thanks to Sumit.xls");
    }  
    else                 //other browser not tested on IE 11
        sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));  

    return (sa);
}

Just create a blank iframe:

<iframe id="txtArea1" style="display:none"></iframe>

Call this function on:

<button id="btnExport" onclick="fnExcelReport();"> EXPORT </button>

Export Html Table To Excel Spreadsheet using jQuery, How do I export data from HTML table in Excel using jquery? Im having issue in exporting the HTML table on IE and Google chrome browsers, The table has 2513 Lines of table data. I read on the Form google chrome has a bug for URL limiting. If i remove some

Datatable plugin solves the purpose best and allows us to export the HTML table data into Excel , PDF , TEXT. easily configurable.

Please find the complete example in below datatable reference link :

https://datatables.net/extensions/buttons/examples/html5/simple.html

(screenshot from datatable reference site)

Export Html Table to Excel file is not working!, How do I export data from HTML table to Excel? Export table to excel using javascript in both chrome and internet explorer. How to export HTML table data to excel. Javascript fetch not working in internet

This could help

function exportToExcel(){
var htmls = "";
            var uri = 'data:application/vnd.ms-excel;base64,';
            var 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>{table}</table></body></html>'; 
            var base64 = function(s) {
                return window.btoa(unescape(encodeURIComponent(s)))
            };

            var format = function(s, c) {
                return s.replace(/{(\w+)}/g, function(m, p) {
                    return c[p];
                })
            };

            htmls = "YOUR HTML AS TABLE"

            var ctx = {
                worksheet : 'Worksheet',
                table : htmls
            }


            var link = document.createElement("a");
            link.download = "export.xls";
            link.href = uri + base64(format(template, ctx));
            link.click();
}

save html as xls - JS save dialog error, I want to export the html table data to excel using either java script or jquery, This script works fine in Mozilla Firefox,it pops-up with a dialog box of excel But when I tested same script in Chrome browser it is not working as  In this tutorials, we will learn about how to export HTML table data to excel using client-side JavaScript. The Client-side export data functionality makes any web application more user-friendly. Using JavaScript, we can export or download HTML table data in excel format without page refresh.

http://wsnippets.com/export-html-table-data-excel-sheet-using-jquery/ try this link it might solve your problem

Export Html table into Excel, Export html table data to Excel using JavaScript / JQuery is not working properly in This script works fine in Mozilla Firefox,it pops-up with a dialog box of excel and ask But when I tested same script in Chrome browser it is not working as  Using JavaScript, the HTML table data can be easily exported without page refresh. In this tutorial, we will show you how to export HTML table data to excel using JavaScript. The JavaScript export functionality can be used in the member list, product list, or other lists to download the data list in excel file format. Export HTML Table Data to

Instead of using window.open you can use a link with the onclick event. And you can put the html table into the uri and set the file name to be downloaded.

Live demo :

function exportF(elem) {
  var table = document.getElementById("table");
  var html = table.outerHTML;
  var url = 'data:application/vnd.ms-excel,' + escape(html); // Set your html table into url 
  elem.setAttribute("href", url);
  elem.setAttribute("download", "export.xls"); // Choose the file name
  return false;
}
<table id="table" border="1">
  <tr>
    <td>
      Foo
    </td>
    <td>
      Bar
    </td>
  </tr>
</table>

<a id="downloadLink" onclick="exportF(this)">Export to excel</a>

clarketm/TableExport: The simple, easy-to-implement , Hi guys I am trying to export an HTML table to Excel file! I have done window.​open('data:application/vnd.ms-excel,' + Are you saying it does not work in IE 9 , yet it works in some other browsers? i only tried it on IE9, Firefox, and Chrome! src="http://code.jquery.com/jquery-1.9.0.js"></script>; <script  When the Export to Excel button is clicked, the jQuery table2excel plugin is applied to the created HTML table.The jQuery table2excel plugin accepts the file name as a parameter which sets the name of the Excel file.

Export HTML Table Data to CSV, Excel, PNG, PDF, JSON & XML , from this topicExport html table data to Excel using JavaScript JQuery is not work working properly in chrome browse (Note: I cant reply there because I have not getElementById('export'); // id of table var lines = tab.rows.length; // the first aktivate so see the result (press F12 in browser) var ua = window.navigator​. However, the answer given in this other StackOverflow question might be just what you need because it does work in Chrome: Export html table data to Excel using JavaScript / JQuery is not working properly in chrome browse; The answer basically involves the use of a custom JavaScript function to present similar functionality to what you're

Visualization: Table | Charts, Now to take my work for next level I need to export the html table to "Excel". The below code is working fine in google chrome,But I find no luck in IE browser. How to Use custom HTML and JavaScript To Export Data to Excel. the Data from the API to the HTML table Directly. for Chrome, if using a different Browser you

Export Html Table To Excel Spreadsheet using jQuery - table2excel Export Table & JSON Data To Excel With jQuery - ExportToExcel · Exporting Html Tables To 2, < script src = "src/jquery.table2excel.js" ></ script > 1, $( "button" ).click( function (){ 6, filename: "SomeFile" , //do not include extension  Here Mudassar Ahmed Khan has explained with an example, how to convert (export) HTML Table to Excel file using jQuery. This article will explain how to convert (export) HTML Table to Excel file with the help of the jQuery table2excel plugin. TAGs: Excel, jQuery, HTML, Table

Comments
  • Test case is for chrome
  • Above test case fails if you are using open source product LibreOffice and Chrome browser. But if you have MS Office installed then code wil work properly.
  • if not then for what this line is?? var txt = document.getElementById('txtArea1').contentWindow;
  • In Chrome, when you click the download button nothing happens at all when using this method. No console errors or anything.
  • Perfect +1 !!! Its working in IE 11, Chrome 35, Firefox 29, Opera 17 But not working in safari 5.1.7 !!! :(
  • how can I change Randome name . I wnat set specefic name .
  • "The file format and extension of download.xls don't match" This is not making the manager happy :/ Any ideas?
  • OMG! This is an awesome plugin!... and has several plugins embedded!! Export, Sort, Reorder, Print Preview, etc... Solved all my data showing needs in just 1 shot!
  • Can I apply styles to my excel using this plugin?
  • @Addy this is a DataTables only solution though, right?