首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

导出excel表有关问题

2012-06-20 
导出excel表问题Java codepackage cn.edu.cumt.printimport java.io.Fileimport java.io.IOExceptionim

导出excel表问题

Java code
package cn.edu.cumt.print;import java.io.File;import java.io.IOException;import java.sql.SQLException;import java.util.List;import cn.edu.cumt.print.ExcelService;import cn.edu.cumt.UserDao.StuDetailedInfoDao;import cn.edu.cumt.realclass.simpleInfoBean;import jxl.Sheet;import jxl.Workbook;import jxl.read.biff.BiffException;import jxl.write.Label;import jxl.write.WritableSheet;import jxl.write.WritableWorkbook;public class ExcelService {        public static boolean writeExcel() throws SQLException, IOException,BiffException {     try {        File file = new File("result.xls");        if(file.exists())        {            return false;         }        else        {            WritableWorkbook wb = Workbook.createWorkbook(new File("D:/result.xls"));             WritableSheet ws = wb.createSheet("sheet1", 0);            StuDetailedInfoDao sdid = new StuDetailedInfoDao();                        List<simpleInfoBean> list = sdid.selectAll();            Label la = new Label(0, 0, "序号");            Label lb = new Label(1, 0, "学生姓名");             Label lc = new Label(2, 0, "性别");            Label ld = new Label(3, 0, "考试级别");             Label le = new Label(4, 0, "考试代码");            Label lee = new Label(5,0, "联系电话");            Label lf = new Label(6, 0, "身份证号");             Label lg = new Label(7, 0, "民族代码");            Label lh = new Label(8, 0, "是否补考");            Label li = new Label(8, 0, "远准考证号");            ws.addCell(la); ws.addCell(lb);            ws.addCell(lc); ws.addCell(ld);            ws.addCell(le); ws.addCell(lee);            ws.addCell(lf);ws.addCell(lg);             ws.addCell(lh); ws.addCell(li);             if (null != list)            {                  for (int i = 0; i < list.size(); i++)                 {                      simpleInfoBean ub = list.get(i);                      la = new Label(0, i + 1, ub.getStuName());                     lb = new Label(1, i + 1, ub.getSex());                      lc = new Label(2, i + 1, ub.getExamGrade());                      ld = new Label(3, i + 1, ub.getCode());                     le = new Label(4, i + 1, ub.getConNum());                     lee = new Label(5, i + 1,ub.getIDcard());                     lf = new Label(6, i + 1, ub.getNationalityCode());                      lg = new Label(7, i + 1, ub.getNationalityCode());                     lh = new Label(8, i + 1, ub.getMakeUpJob());                      li = new Label(9, i + 1, ub.getAdmissionCardNum());                     ws.addCell(la); ws.addCell(lb);                     ws.addCell(lc); ws.addCell(ld);                      ws.addCell(le); ws.addCell(lee);                      ws.addCell(lf); ws.addCell(lg);                      ws.addCell(lh); ws.addCell(li);                                      }             }            wb.write();             wb.close();             return true;        }     } catch (Exception e) {          e.printStackTrace();         return false;         //     TODO: handle exception }              }}    }//exportXLS.jsp<body><%    if(ExcelService.writeExcel())    {            %><p>成功生成终表,现在<a href="D:/result.xls">下载</a></p><%    }    else    {%><p>插入失败,请去E盘查看文件“result.xls”是否已经存在</p><%    }%></body>

报错了:
An error occurred at line: 12 in the jsp file: /exportXLS.jsp
The type jxl.read.biff.BiffException cannot be resolved. It is indirectly referenced from required .class files
9: </head>
10: <body>
11: <%
12: if(ExcelService.writeExcel())
13: {
14:
15:
Stacktrace:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)


at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
必要的jar包我已经导入了

[解决办法]
jxl.read.biff.BiffException cannot be resolved.

这个错误很有意思哦。我有2个想法,你自己测试看看
1 你的jar损坏了,别不相信,我遇到过,你重新下一个,然后解压缩看看里面是否有这个class
2 你的jar版本不对,也许太老了,也许太新了,总之,和前面一下,解压缩看一下。
[解决办法]
导出Excel表没这么麻烦啊,在page标签中加上 contentType="application/vnd.ms-excel;charset=gbk"就可以了啊

热点排行