/**
* 导出列表为excel
* @param request
* @param response
* @return
* @throws BusinessException
*/
public ModelAndView exportExcel(HttpServletRequest request, HttpServletResponse response) throws BusinessException{
//查询记录集
List resultVO = null;
try{
resultVO = null;//得到一个list
}catch (Exception e) {
hashMap.put("errorMessage", e);
return new ModelAndView(failView, hashMap);
}
//总共要导出的记录数
int totleCount = resultVO.getTotalRowCount();
if(totleCount==0){
hashMap.put("errorMessage", new BusinessException("p.jbeduhai.0")); //属性文件定义code
return new ModelAndView(failView, hashMap);
}
String fileName = "xxxxxx";
response.reset();//清空输出流
response.setHeader("content-disposition","attachment;filename="+ fileName +".xls");
response.setContentType("application/msexcel");//定义输出类型
OutputStream os = null;
WritableWorkbook book = null;
try{
os = response.getOutputStream();//取得输出流
book = Workbook.createWorkbook(os);
}catch (Exception e) {
throw new SystemException("建立excel文件输出流时发生异常",e);
}
//第几个工作区
int sheetNum = 1;
NumberFormat nf = new jxl.write.NumberFormat("#0.00");
WritableCellFormat wcfN = new WritableCellFormat(nf);
Number labelNF;
QueryVO cell; //显示 vo类定义
WritableSheet sheet = null; //设置工作区
int row = 0;//行
List tcList = null;//得到一个list
for(int i=0; i <= totleCount/pageSize;i++){
try{
resultVO =null
}catch (Exception e) {
hashMap.put("errorMessage", e);
return new ModelAndView(failView, hashMap);
}
tcList = resultVO.getDataList();
for (QueryVO qcVO : tcList) {
//判断是否超过当前工作区显示的的最大条数
if(row==0 || row > maxRecord){
//判断是否要创建新的工作区
try {
sheet = getSheet(book, sheetNum);
} catch (Exception e) {
throw new SystemException("新建excel工作区时发生异常",e);
}
row = 1;
sheetNum++;
}
cell = qcVO;
try {
sheet.addCell(new Label(0,row,cell.getTbId().toString()));
sheet.addCell(new Label(1,row,"aaa");
labelNF = new Number(2,row,cell.getxx().doubleValue(), wcfN);
sheet.addCell(labelNF);//输出数据为number型
labelNF = new Number(3,row,cell.getxx().doubleValue(), wcfN);
sheet.addCell(labelNF);//输出数据为number型
sheet.addCell(new Label(4,row,"ccc");
}catch (Exception e) {
throw new SystemException("写excel文件记录时发生异常",e);
}
row ++;
}
pageNum++;
}
try {
book.write();
book.close();
os.close();
} catch (IOException e) {
throw new SystemException("关闭文件输出流时发生异常",e);
}
return null;
}
分享到:
相关推荐
Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面。Spring 框架提供了构建 Web 应用程序的全功能 MVC 模块。Spring MVC4是当前zuixin的版本,在众多特性上有了进一步的提升。, 在精通Spring...
spring3mvc导入包大全。里面拥有spring3MVC框架搭建的必备包。新手学习spring3必备
可以前往查看本人CSDN博客《Jxls+Spring MVC实现Excel导出》
基于spring mvc的Excelweb的报表项目,使用spring data jpa、spring security、spring mvc搭建工程 特有的EXCEL+绑定数据列的报表设计方式,行列对称,能够轻松处理复杂的报表展现样式,部署方式简单而灵活,具有...
可以前往查看本人CSDN博客《Jxls+Spring MVC实现Excel导出》
在数据管理系统中,添加大量数据,如果通过手动录入的话,相当费事费力。最近开发一款数据管理系统,所以我花了半天时间将该功能梳理出来。该资料将框架和其他功能都简化,主要实现该功能。
8.Spring MVC 下载 Excel 文档的需求案例 9.Spring MVC RESTful 风格的请求方式案例 10.Spring + Spring MVC + JDBCTemplate 整合并通过 RESTful 风格获取所有用户信息案例 11.Spring MVC 数据绑定案例 12.Spring ...
基于spring mvc、spring、hibernate、bootstrap、maen开发的企业级项目,导入即可运行
本文详细介绍spring MVC的原理和开发心得体会。
NULL 博文链接:https://dengli19881102.iteye.com/blog/1006011
精通Spring MVC 4 中文
spring框架,导入excel中的数据到数据库,导出数据库数据到excel文件
Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于...
NULL 博文链接:https://vernonchen163.iteye.com/blog/1953520
Spring MVC是Spring框架中用于Web应用快速开发的一个模块,其中的MVC是Model-View-Controller的缩写。作为当今业界最主流的Web开发框架,Spring MVC已经成为当前最热门的开发技能,同时也广泛用于桌面开发领域。 ...
spring MVC数据绑定 含例子 转载自疯芒毕露的专栏 刚开始用spring mvc 做web开发时 经常会不知道如何合适绑定页面数据 用惯struts2的朋友更认为spring mvc 绑定数据不如struts2方便 本人最开始也是这么认为 经过一段...
Spring MVC所需jar包,包含java开发中 Spring MVC架构中最常用的jar包
关于构建Sping MVC的Jar包,包括Sping2.5.6和Hibernate3.6.8