File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Export excel using jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Export excel using jsp " Watch "Export excel using jsp " New topic

Export excel using jsp

Arunkumar Chinnadurai
Ranch Hand

Joined: Dec 15, 2011
Posts: 56

<%@ page contentType="application/" %>
<title>Inserting data in Excel Sheet Using JSP</title>
<tr><th colspan="4"><b>RoseIdia Pvt Ltd.
Team detail</b></th></tr>
<th>Designation </th>
<th>Contact Number</th>
<th>Email Id</th>
<td>Rajesh kumar</td>
<td>Software Deveploper</td>
<td>Santosh Kumar</td>
<td>Web Designer</td>
<td>Team Leader</td>

any body help me out from this ....
its not working.....
Victor M. Pereira
Ranch Hand

Joined: Mar 02, 2012
Posts: 50
You could try searching for tag libraries. Try jmesa.

Is very similar to oracle's rich table faces implementation.

Victor M. Pereira
Tim Moores

Joined: Sep 21, 2011
Posts: 2408
Display Tag is another good one.
Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 147

JSP is for outputting HTML or XML. Excel is neither. What you are creating is an HTML table, and then hoping that Excel will be smart enough to automatically import it.

If you want to generate Excel formatted files (like your content type suggests), look at Apache POI. I would also highly recommend implementing it as a Servlet rather than a JSP template, since JSP is not intended or designed for this type of content.

In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
Arunkumar Chinnadurai
Ranch Hand

Joined: Dec 15, 2011
Posts: 56

Hi All,

first thanks to all for replying this..

I did this using POI.....if i use POI Libraries i can use it on servlet only....

I want to export html table to excel ......

from a button click....
Arunkumar Chinnadurai
Ranch Hand

Joined: Dec 15, 2011
Posts: 56

ldu=new LeaveDetailsUtility();
System.out.println("Inside of Export Button.....!!!"+ses.getAttribute("rptObject")+"\t Year : "+ses.getAttribute("Year"));
ArrayList<WorkingDays> al=(ArrayList<WorkingDays>)ses.getAttribute("rptObject");

WorkingDays w=new WorkingDays();
Iterator i=al.iterator();

// ExportToExcel ee=new ExportToExcel();
// ee.exportLeaveDetailsYearlyReport(al);

PrintWriter out = response.getWriter();

ResourceBundle rb=ResourceBundle.getBundle("resource.LeaveDetailsYearlyReport_Property");
// rb.getString("ReportHeading");

// String filename="c:/LeaveDetails_Yearly_Report_"+(new Date()).getTime()+".xls" ;
String filename="C:\\Reports\\LeaveDetails_Yearly_Report_"+(new Date()).getTime()+".xls";
HSSFWorkbook hwb=new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("LeaveDetailsYearlyReport");

HSSFRow heading= sheet.createRow((short)0);
heading.createCell((short) 0).setCellValue(rb.getString("ReportHeading"));

HSSFRow rowhead= sheet.createRow((short)1);
rowhead.createCell((short) 0).setCellValue(rb.getString("FirstRowField1"));
rowhead.createCell((short) 1).setCellValue(rb.getString("FirstRowField2"));
rowhead.createCell((short) 2).setCellValue(rb.getString("Mon1"));
rowhead.createCell((short) 3).setCellValue(rb.getString("Mon2"));
rowhead.createCell((short) 4).setCellValue(rb.getString("Mon3"));
rowhead.createCell((short) 5).setCellValue(rb.getString("Mon4"));
rowhead.createCell((short) 6).setCellValue(rb.getString("Mon5"));
rowhead.createCell((short) 7).setCellValue(rb.getString("Mon6"));
rowhead.createCell((short) 8).setCellValue(rb.getString("Mon7"));
rowhead.createCell((short) 9).setCellValue(rb.getString("Mon8"));
rowhead.createCell((short) 10).setCellValue(rb.getString("Mon9"));
rowhead.createCell((short) 11).setCellValue(rb.getString("Mon10"));
rowhead.createCell((short) 12).setCellValue(rb.getString("Mon11"));
rowhead.createCell((short) 13).setCellValue(rb.getString("Mon12"));
rowhead.createCell((short) 14).setCellValue(rb.getString("LastColumn"));

int rowCount=2;

HSSFRow row= sheet.createRow((short)rowCount);
row.createCell((short) 0).setCellValue(w.getWorkingYear());
row.createCell((short) 1).setCellValue(w.getEmpID());
row.createCell((short) 2).setCellValue(w.getJan());
row.createCell((short) 3).setCellValue(w.getFeb());
row.createCell((short) 4).setCellValue(w.getMar());
row.createCell((short) 5).setCellValue(w.getApr());
row.createCell((short) 6).setCellValue(w.getMay());
row.createCell((short) 7).setCellValue(w.getJun());
row.createCell((short) 8).setCellValue(w.getJul());
row.createCell((short) 9).setCellValue(w.getAug());
row.createCell((short) 10).setCellValue(w.getSep());
row.createCell((short) 11).setCellValue(w.getOct());
row.createCell((short) 12).setCellValue(w.getNov());
row.createCell((short) 13).setCellValue(w.getDec());
row.createCell((short) 14).setCellValue(w.getTotalWorkingDays());
System.out.println("Get Values : "+w.getWorkingYear()+"\t Emp Id : "+w.getEmpID()+"\t Row Count : "+rowCount);

File f=new File(filename);
FileOutputStream fileOut = new FileOutputStream(f);

RequestDispatcher rd=request.getRequestDispatcher("LeaveDetailsYearlyReport.jsp?Year="+ses.getAttribute("Year"));
Bear Bibeault ,

thanks for your kind info.
i realised whatt i have done .
i trying to improve my questioning skill....
I agree. Here's the link:
subject: Export excel using jsp
Similar Threads
best option for implementing form
Problem with Simple JSP page
Validation Issues
How to store values in session using struts 2 and then how to retrieve values in a jsp
HTML Table Column Widths