Thursday 10 October 2013

How to convert and download HTML Format into ( MS_Excel, Excel , Xls) Formats in jsp


In this code i am showing you, How to convert any HTML or jsp code into ( MS_Excel, Excel , Xls) formats,
and also you can download same format in to Excel , xls. It is very usefull when you will generating a report with download feature in excel format.

 

//---------------------- Save As "GetExcel.jsp" -------------------//

<table width="60%" cellpadding="5px;" align="center" border="1" style="border-color: RED;"  class="textn">
  <tbody bgcolor="#ffdebf">
   <tr>
 <td colspan="3"><strong>Convert HTML code in to Excel format and also download it </strong></td>
   <br/>
   </tr>
  </tbody>
  </table>

<table width="60%" align="center" border="1" style="border-collapse: collapse; border-color: #df6e00;" bordercolor="#111111" class="textn">
 
  <th style="">Emp Name</th>  
 <th>Emp ID</th>
    <th>Mobile</th>
    <th>City</th>
<tr>
  <td>
      <center>Aman Kumar</center> 
</td>
<td>
      <center>1099</center> 
</td>
<td>
      <center>9918299393</center> 
</td>
<td>
      <center>Noida</center> 
</td> 
  </tr>
<tr>
  <td>
      <center>Nitin Kumar</center> 
</td>
<td>
      <center>1233</center> 
</td>
<td>
      <center>956829937</center> 
</td>
<td>
      <center>Ghaziabad</center> 
</td> 
  </tr>
<tr>
  <td>
      <center>Brijesh Bhagat</center> 
</td>
<td>
      <center>1405</center> 
</td>
<td>
      <center>9338299345</center> 
</td>
<td>
      <center>Lucknow</center> 
</td> 
  </tr>
<tr>
  <td>
      <center>Suraj Kumar</center> 
</td>
<td>
      <center>2035</center> 
</td>
<td>
      <center>9938244340</center> 
</td>
<td>
      <center>New Delhi</center> 
</td> 
  </tr>

</table>

<P align="center"><a href="DownloadExcel.jsp" style="color:Blue;">Download Excel</a></P>



//---------------------- Save As "DownloadExcel.jsp" -------------------//


 <%   
     response.setHeader("Content-Disposition","attachment;filename=Report.xls");   
     response.setContentType("application/vnd.excel");  
 %> 

<table width="60%" align="center" border="1" style="border-collapse: collapse" bordercolor="#111111" class="textn">
<tr>
  
<td colspan="3"><strong>Download Report:</strong></td>
<br/>
</tr>

</table>

<table width="60%" align="center" border="1" style="border-collapse: collapse" bordercolor="#111111" class="textn">
 
  <th style="">Emp Name</th>  
 <th>Emp ID</th>
    <th>Mobile</th>
    <th>City</th>
<tr>
  <td>
      <center>Aman Kumar</center> 
</td>
<td>
      <center>1099</center> 
</td>
<td>
      <center>9918299393</center> 
</td>
<td>
      <center>Noida</center> 
</td> 
  </tr>
<tr>
  <td>
      <center>Nitin Kumar</center> 
</td>
<td>
      <center>1233</center> 
</td>
<td>
      <center>956829937</center> 
</td>
<td>
      <center>Ghaziabad</center> 
</td> 
  </tr>
<tr>
  <td>
      <center>Brijesh Bhagat</center> 
</td>
<td>
      <center>1405</center> 
</td>
<td>
      <center>9338299345</center> 
</td>
<td>
      <center>Lucknow</center> 
</td> 
  </tr>
<tr>
  <td>
      <center>Suraj Kumar</center> 
</td>
<td>
      <center>2035</center> 
</td>
<td>
      <center>9938244340</center> 
</td>
<td>
      <center>New Delhi</center> 
</td> 
  </tr>
</table>

No comments:

Post a Comment