Saturday, January 11, 2014

Export table to excel using jQuery

Hi dear ,

To export table tag to excel , 
you can use window.open() method .

Refrence :

window.open(MIMEtype , replace);
  • MiMEtype (optional) : Defult Value is "text/html". the type of document .
  • replace (optional) : The document which opened this document.

export table to excel with jQuery
Example source code for export table tag to excel with jQuery :



$('#excel_button').click(function(e){

    window.open('data:application/vnd.ms-excel,' + $('#result_data').html());
    e.prevenetDefult();
});



HTML Button :
<input type="button" id="excel_button" value=" Export Table Tag To Excel" />

HTML Table :

<table id="result_data">
    <tr>
        <th>Column One </th>
        <th>Column Two</th>
        <th>Column Three</th>
    </tr>
    <tr>
        <td>row1 Col1</td>
        <td>row1 Col2</td>
        <td>row1 Col3</td>
   </tr>
   <tr>
        <td>row2 Col1</td>
        <td>row2 Col2</td>
        <td>row2 Col3</td>
   </tr>
      <tr>
        <td>row3 Col1</td>
        <td>row3 Col2</td>
        <td>row3 Col3</td> 
   </tr>
</table>

Heading HTML Source :
if you used Utf8 encoding source :   
    <meta charset="UTF-8" />
jQuery Refrence :
    <script src="http://code.jquery.com/jquery-1.10.2.js"></script>

No comments:

Post a Comment