aspose file tools*
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 JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Export excel using jsp " Watch "Export excel using jsp " New topic
Author

Export excel using jsp

Arunkumar Chinnadurai
Ranch Hand

Joined: Dec 15, 2011
Posts: 56

<%@ page contentType="application/vnd.ms-excel" %>
<html>
<head>
<title>Inserting data in Excel Sheet Using JSP</title>
</head>
<body>
<table>
<tr><th colspan="4"><b>RoseIdia Pvt Ltd.
Team detail</b></th></tr>
<tr>
<th>Name</th>
<th>Designation </th>
<th>Contact Number</th>
<th>Email Id</th>
</tr>
<tr>
<td>Rajesh kumar</td>
<td>Software Deveploper</td>
<td>9891589173</td>
<td>rajeshpatel_04@yahoo.co.in</td>
</tr>
<tr>
<td>Santosh Kumar</td>
<td>Web Designer</td>
<td>9350534522</td>
<td>skashyapshan@gmail.com</td>
</tr>
<tr>
<td>Chandan</td>
<td>Team Leader</td>
<td>9911544678</td>
<td>chandan3verma@gmail.com</td>
</tr>
</table>
</body>
</html>

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.


regards,
Victor M. Pereira
Tim Moores
Rancher

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.


OCPJP
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

ses=request.getSession();
ldu=new LeaveDetailsUtility();
if(request.getParameter("btnExport")!=null)
{
if(request.getParameter("btnExport").equals("Export"))
{
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);

response.setContentType("text/html");
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;

while(i.hasNext())
{
w=(WorkingDays)i.next();
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());
rowCount=rowCount+1;
System.out.println("Get Values : "+w.getWorkingYear()+"\t Emp Id : "+w.getEmpID()+"\t Row Count : "+rowCount);
}

File f=new File(filename);
if(!f.exists())
{
f.createNewFile();
}
FileOutputStream fileOut = new FileOutputStream(f);
hwb.write(fileOut);
fileOut.close();

RequestDispatcher rd=request.getRequestDispatcher("LeaveDetailsYearlyReport.jsp?Year="+ses.getAttribute("Year"));
rd.forward(request,response);
}
}
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: http://aspose.com/file-tools
 
subject: Export excel using jsp