Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Export excel using jsp

 
Ranch Hand
Posts: 56
Android MyEclipse IDE Windows XP
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<%@ 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.....
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could try searching for tag libraries. Try jmesa.

Is very similar to oracle's rich table faces implementation.
 
Saloon Keeper
Posts: 6971
164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Display Tag is another good one.
 
Ranch Hand
Posts: 147
Eclipse IDE Tomcat Server Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Arunkumar Chinnadurai
Ranch Hand
Posts: 56
Android MyEclipse IDE Windows XP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 56
Android MyEclipse IDE Windows XP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic