Bonjour,
J'aimerais créer une feuille excel à partir d'une JSP. J'utilise tomcat 5.0, POI 20050704. j'ai créer un bean de ce type :
et un jsp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 package servlets.index; import org.apache.poi.hssf.usermodel.*; import java.util.Date; import java.io.*; public class POIExample { private String file = ""; public String genDATAFile() throws IOException { System.out.println("POIExample: Generating output excel file."); System.out.println("POIExample: Start Time= "+ new Date()); //New Workbook HSSFWorkbook wb = new HSSFWorkbook(); FileOutputStream fileOut = new FileOutputStream("workbook.xls"); // New Sheet HSSFSheet sheet1 = wb.createSheet("new sheet"); HSSFSheet sheet2 = wb.createSheet("second sheet"); wb.write(fileOut); // Creating Cells HSSFSheet sheet = wb.createSheet("new sheet"); // Create a row and put some cells in it. Rows are 0 based. HSSFRow row = sheet.createRow((short)0); // Create a cell and put a value in it. HSSFCell cell = row.createCell((short)0); cell.setCellValue(1); // Or do it on one line. row.createCell((short)1).setCellValue(1.2); row.createCell((short)2).setCellValue("This is a string"); row.createCell((short)3).setCellValue(true); // Write the output to a file wb.write(fileOut); // Creating Date Cells // Create a row and put some cells in it. Rows are 0 based. // Create a cell and put a date value in it. The first cell is not styled // as a date. cell.setCellValue(new Date()); // we style the second cell as a date (and time). It is important to // create a new cell style from the workbook otherwise you can end up // modifying the built in style and effecting not only this cell but other cells. HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm")); cell = row.createCell((short)1); cell.setCellValue(new Date()); cell.setCellStyle(cellStyle); // Write the output to a file wb.write(fileOut); fileOut.close(); return this.file; } }
Ma classe java compile mais la jsp me retourne ça :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 <%@ page language="java" contentType="text/html" %> <%@ page import="java.sql.*" %> <%@ page import="java.lang.*" %> <%@ page import=" java.util.Date.*" %> <%@ page import=" java.io.*" %> <jsp:useBean id="POIExample" scope="request" class="servlets.index.POIExample"> <jsp:setProperty name="POIExample" property="*" /> </jsp:useBean> <html> <title>POI Example</title> <body bgcolor="#FFFFFF" topmargin="1" leftmargin="1" marginwidth="1" marginheight="1" link="#000000" vlink="#000000" alink="#000000"> <table width="100%" height="100%" bgcolor="#cccc99" border="0" cellspacing="2" cellpadding="0"> <tr> <td align=center valign=center> <TABLE BORDER=1> <TR> <TD> <table width="175" height="110" bgcolor="#ffffff" border="0" cellspacing="0" cellpadding="3"> <tr> <td align=center><a href="datafile/<%= POIExample.genDATAFile() %>" target="new">POI Example</a></td> </tr> <tr> <td align=center><input type=button onclick="window.close()" value="Close Window"></td> </tr> </table> </TD> </TR> </TABLE> </td> </tr> </table> </body> </html>
exception javax.servlet.ServletException: org/apache/poi/hssf/usermodel/HSSFWorkbook org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758) org.apache.jsp.excel2_jsp._jspService(excel2_jsp.java:112) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
cause mère java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook servlets.index.POIExample.genDATAFile(POIExample.java:21)
Est ce qu'il y a un fichier xml a configurer pour que le POI soit reconnu ?Merci d'avance pour votre coup de main
Partager