Solution 1 :

//Add this function to script tag

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

            for(j = 0 ; j < tab.rows.length ; j++) 

            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
                sa=txtArea1.document.execCommand("SaveAs",true,"Say Thanks to Sumit.xls");
            else                 //other browser not tested on IE 11
                sa ='data:application/,' + encodeURIComponent(tab_text));  

            return (sa);

Problem :

I’m trying to get my datbase fetched data to Excel file to download it in execl or csv, but I’m having problems with exporting. Not datas are fetching to the csv .Here is my code:

<div><a href="javascript:void(0)" id="export-to-csv">Export to csv</a></div>
 <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" id="export-form">
                        <input type="hidden" value='' id='hidden-type' name='ExportType'/>
      <table id="data-table" class="table table-bordered table-striped">
          <tr style="background-color: cornflowerblue;">
            <th>Invoice No.</th>
            <th>Invoice Date</th>
            <th>Student Name</th>
            <th>Total Amount</th>



    if($total_rows > 0)
      foreach($all_result as $row)
        echo '



Comment posted by Ketan Yekale

What are $total_rows and $all_result?

Comment posted by…

please find this link

Comment posted by Tabish Tanseef

also add this line in your html code