ExcelUtils的User's Guide http://excelutils.sourceforge.net/UserGuide.html
这里有个很清楚的测试例子可以看一下:http://hi.baidu.com/henyue/blog/item/f24eb17edec19e340cd7dacf.html
我在这里就写在Web中的应用了:
1. 首先在项目加入以下五个jar包:
- excelutils.jar
- poi-2.5.1.jar
- commons-logging.jar
- commons-digester.jar
- commons-beanutils.jar
2. 建立一个Excel模板
3. 在Action中
/**
* 导出报表
* @param response
* @return
* @throws ExcelException
* @throws IOException
*/
@Action("/finishbillInfoExport")
public String finishbillInfoExport(){
String CMaketabletime = Struts2Utils.getParameter("CMaketabletime");
String CTrainsetid = Struts2Utils.getParameter("CTrainsetid");
String CTrainsetno = Struts2Utils.getParameter("CTrainsetno");
String CTrackname = Struts2Utils.getParameter("CTrackname");
mapList = finishbillInfoService.queryFinishbillDetail();
if(!("undefined".equals(CMaketabletime))){
ExcelUtils.addValue("CMaketabletime", CMaketabletime);
}
if(!("undefined".equals(CTrainsetid))){
ExcelUtils.addValue("CTrainsetid", CTrainsetid);
}
if(!("undefined".equals(CTrainsetno))){
ExcelUtils.addValue("CTrainsetno", CTrainsetno);
}
if(!("undefined".equals(CTrackname))){
ExcelUtils.addValue("CTrackname", CTrackname);
}
ExcelUtils.addValue("details", mapList);
String path = "/pages/assignment/templates/finishbillDetails.xls";
try {
HttpServletResponse response = ServletActionContext.getResponse();
response.reset();
response.setCharacterEncoding( "UTF-8" );
response.setHeader( "Content-disposition", "attachment; filename=" + System.currentTimeMillis()+".xls");
response.setContentType("application/msexcel");
ExcelUtils.export(ServletActionContext.getServletContext(),path,response.getOutputStream());
} catch (ExcelException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
4.结果如下图:
- 大小: 21.2 KB
- 大小: 35.2 KB
分享到:
相关推荐
ExcelUtils工具类支持按照固定模板导出Excel,简单、易上手
Excel VBA 快速上手教程,对新手很有用的。
Excel_VBA_快速上手,和大家一起分享
Excel VBA之快速上手(DOC) Excel VBA之快速上手(DOC)
springboot 入门简单上手 helloword代码例子
易学C++ 简单上手,让你轻松学易学C++ 简单上手,让你轻松学易学C++ 简单上手,让你轻松学易学C++ 简单上手,让你轻松学易学C++ 简单上手,让你轻松学易学C++ 简单上手,让你轻松学易学C++ 简单上手,让你轻松学易学C++ ...
Excel VBA 之快速上手,DOC格式,简单明了,通俗易懂。
VBA 快速学习宝典,包含很多实用的函数,大家不要错过,很实用的,
Excel VBA 之快速上手 Excel VBA 基础
FLEX运动腕带简易上手教程
完全手册Excel_VBA典型实例大全:通过368个例子掌握,Excel_VBA_之快速上手
lingo简易上手入门教程三份
mvp demo 亲测可用 简单 适合新手上手,框架,构架,mvp demo 亲测可用 简单 适合新手上手,框架,构架
winform 打印 简单上手的例子 winform 打印 简单上手的例子