在action里生成excel文档,第一次操作成功但是第二次生成excel就出现错误。请大家帮忙看看。代码:
try {
List dataList = todayService.retrieve(todayService
.makeSearchWhere(todayForm)); if (dataList != null && dataList.size() > 0) {
String realPath = this.getServlet().getServletContext()
.getRealPath(File.separator);
String excelPath = realPath + File.separator + "template"
+ File.separator + "todaypresentdetail.xls";
// 读取模板
Workbook wb = Workbook.getWorkbook(new File(excelPath));
response.reset();
response.setHeader("content-disposition",
"attachement;filename=todaypresentdetail.xsl");
response
.setContentType("application/vnd.ms-excel; charset=UTF-8");
if(os == null){
os = response.getOutputStream();
}
WritableWorkbook book = Workbook.createWorkbook(os, wb);
// 读取工作簿
WritableSheet sheet = book.getSheet(0);
// 设置各种单元格格式
setOutDateFormat();
setLeftEdgeFormat();
setFontCenterFormat();
setFontLeftFormat();
setNumberFormat();
setSubTotalFtFormat();
setSubTotalNumFormat();
// 出库日区间
Label outDate = new Label(1, 2,
todayForm.getOutDateFrom()
+ " 〜 " + todayForm.getOutDateTo(), fontLeftFormat);
sheet.addCell(outDate);
Label createDate = new Label(5,2,Utility.getCurrentDate());
sheet.addCell(createDate);
for (int i = 0; i < dataList.size(); i++) {
TodayPresentShow viewBean = (TodayPresentShow) dataList
.get(i);
// No.
Label No = new Label(0, 6+ i, String.valueOf(i + 1),
leftEdgeFormat);
sheet.addCell(No);
// 综合类型
Label synthesisType = new Label(1, 6 + i, viewBean.getStat_type()
, fontCenterFormat);
sheet.addCell(synthesisType);
// 店铺/客户名
Label shopName = new Label(2, 6 + i, viewBean.getShop_name()
, fontLeftFormat);
sheet.addCell(shopName);
// 商品名
Label produceName = new Label(3, 6 + i, viewBean.getPresent_name()
, fontLeftFormat);
sheet.addCell(produceName);
// 出库数
Label outNum = new Label(4, 6 + i,viewBean.getNumbers()
, numberFormat);
sheet.addCell(outNum); // 实际出货数
Label actualNum = new Label(5, 6 + i, viewBean.getReal_numbers()
, numberFormat);
sheet.addCell(actualNum);
}
book.write();
os.flush();
book.close();
os.close();
}} catch (Exception e) {
e.printStackTrace();
throw e;
}异常:Warning: Cell at F47 not present - adding a blank
Warning: Some cells exceeded the specified bounds. Resizing sheet dimensions from 9x46 to 9x47
Warning: Cell at F47 not present - adding a blank
Warning: Some cells exceeded the specified bounds. Resizing sheet dimensions from 9x46 to 9x47
java.lang.ArrayIndexOutOfBoundsException: 210
at jxl.biff.IndexMapping.getNewIndex(IndexMapping.java:68)
at jxl.biff.FormattingRecords.rationalize(FormattingRecords.java:385)
at jxl.write.biff.WritableWorkbookImpl.rationalize(WritableWorkbookImpl.java:912)
at jxl.write.biff.WritableWorkbookImpl.write(WritableWorkbookImpl.java:619)
at com.cn.sys.action.subsys_02.TodayPresentExcelAction.retrieve(TodayPresentExcelAction.java:142)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.cn.sys.action.SuperAction.dispatchMethod(SuperAction.java:237)
at com.cn.sys.action.SuperAction.execute(SuperAction.java:161)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
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 com.cn.sys.common.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:36)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cn.sys.common.AuthorizeFilter.doFilter(AuthorizeFilter.java:100)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
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(Thread.java:595)
try {
List dataList = todayService.retrieve(todayService
.makeSearchWhere(todayForm)); if (dataList != null && dataList.size() > 0) {
String realPath = this.getServlet().getServletContext()
.getRealPath(File.separator);
String excelPath = realPath + File.separator + "template"
+ File.separator + "todaypresentdetail.xls";
// 读取模板
Workbook wb = Workbook.getWorkbook(new File(excelPath));
response.reset();
response.setHeader("content-disposition",
"attachement;filename=todaypresentdetail.xsl");
response
.setContentType("application/vnd.ms-excel; charset=UTF-8");
if(os == null){
os = response.getOutputStream();
}
WritableWorkbook book = Workbook.createWorkbook(os, wb);
// 读取工作簿
WritableSheet sheet = book.getSheet(0);
// 设置各种单元格格式
setOutDateFormat();
setLeftEdgeFormat();
setFontCenterFormat();
setFontLeftFormat();
setNumberFormat();
setSubTotalFtFormat();
setSubTotalNumFormat();
// 出库日区间
Label outDate = new Label(1, 2,
todayForm.getOutDateFrom()
+ " 〜 " + todayForm.getOutDateTo(), fontLeftFormat);
sheet.addCell(outDate);
Label createDate = new Label(5,2,Utility.getCurrentDate());
sheet.addCell(createDate);
for (int i = 0; i < dataList.size(); i++) {
TodayPresentShow viewBean = (TodayPresentShow) dataList
.get(i);
// No.
Label No = new Label(0, 6+ i, String.valueOf(i + 1),
leftEdgeFormat);
sheet.addCell(No);
// 综合类型
Label synthesisType = new Label(1, 6 + i, viewBean.getStat_type()
, fontCenterFormat);
sheet.addCell(synthesisType);
// 店铺/客户名
Label shopName = new Label(2, 6 + i, viewBean.getShop_name()
, fontLeftFormat);
sheet.addCell(shopName);
// 商品名
Label produceName = new Label(3, 6 + i, viewBean.getPresent_name()
, fontLeftFormat);
sheet.addCell(produceName);
// 出库数
Label outNum = new Label(4, 6 + i,viewBean.getNumbers()
, numberFormat);
sheet.addCell(outNum); // 实际出货数
Label actualNum = new Label(5, 6 + i, viewBean.getReal_numbers()
, numberFormat);
sheet.addCell(actualNum);
}
book.write();
os.flush();
book.close();
os.close();
}} catch (Exception e) {
e.printStackTrace();
throw e;
}异常:Warning: Cell at F47 not present - adding a blank
Warning: Some cells exceeded the specified bounds. Resizing sheet dimensions from 9x46 to 9x47
Warning: Cell at F47 not present - adding a blank
Warning: Some cells exceeded the specified bounds. Resizing sheet dimensions from 9x46 to 9x47
java.lang.ArrayIndexOutOfBoundsException: 210
at jxl.biff.IndexMapping.getNewIndex(IndexMapping.java:68)
at jxl.biff.FormattingRecords.rationalize(FormattingRecords.java:385)
at jxl.write.biff.WritableWorkbookImpl.rationalize(WritableWorkbookImpl.java:912)
at jxl.write.biff.WritableWorkbookImpl.write(WritableWorkbookImpl.java:619)
at com.cn.sys.action.subsys_02.TodayPresentExcelAction.retrieve(TodayPresentExcelAction.java:142)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.cn.sys.action.SuperAction.dispatchMethod(SuperAction.java:237)
at com.cn.sys.action.SuperAction.execute(SuperAction.java:161)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
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 com.cn.sys.common.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:36)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cn.sys.common.AuthorizeFilter.doFilter(AuthorizeFilter.java:100)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
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(Thread.java:595)
数组越界
Some cells exceeded the specified bounds?
某些单元格的赋值有问题,你打印下值看看,如时间类型,文本类型,金额类型,是否匹配
Warning: Some cells exceeded the specified bounds. Resizing sheet dimensions from 1x458 to 2x458请问使用jxl组件 是怎么解决的?