public String ExcelExport() throws Exception{
HttpServletResponse response = ServletActionContext.getResponse();
// 定义request ,response.
// 查询下载附件.
// 设置下载头信息.begin
response.setCharacterEncoding("UTF-8");
response.setContentType("file");
response.setHeader("Content-Disposition", "attachment; filename="+ new String("报表.xls".getBytes("GB2312"), "iso8859-1"));
// 这个地方一定要进行编码的转换要不然中文字符会出现乱码.
// 设置下载头信息.end,
HttpServletRequest request = ServletActionContext.getRequest();
OutputStream output = null;
InputStream fis = null;
try {
output = response.getOutputStream();
jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(output);
jxl.write.WritableSheet ws = wwb.createSheet("各项产品月销售收入统计汇总表 ", 0);
WritableFont wf = new WritableFont(WritableFont.ARIAL, 10,
WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
jxl.format.Colour.BLACK); // 定义格式 字体 下划线 斜体 粗体 颜色
//创建格式化对象实例
WritableCellFormat totalx2Format = new WritableCellFormat(wf);
//垂直居中
totalx2Format.setVerticalAlignment(VerticalAlignment.CENTRE);
//水平居中
totalx2Format.setAlignment(Alignment.CENTRE);
// 设置标题.ws.addCell(new jxl.write.Label(列, 行, 内容.));
ws.addCell(new Label(0, 1, "单位名称",totalx2Format));
ws.addCell(new Label(1, 1, "神州通(含邮政汇款)",totalx2Format));
ws.addCell(new Label(7, 1, "充值卡",totalx2Format));
ws.addCell(new Label(13, 1, "在线定卡",totalx2Format));
ws.addCell(new Label(15, 1, "本月销售总金额(单位:元)",totalx2Format));
ws.addCell(new Label(1, 2, "20元面值",totalx2Format));
ws.addCell(new Label(3, 2, "25元面值",totalx2Format));
ws.addCell(new Label(5, 2, "50元面值",totalx2Format));
ws.addCell(new Label(7, 2, "30元面值",totalx2Format));
ws.addCell(new Label(9, 2, "50元面值",totalx2Format));
ws.addCell(new Label(11, 2, "100元面值",totalx2Format));
ws.addCell(new Label(13, 2, "数量(张)",totalx2Format));
ws.addCell(new Label(14, 2, "金额(元)",totalx2Format));
ws.addCell(new Label(1, 3, "数量(张)",totalx2Format));
ws.addCell(new Label(2, 3, "金额(元)",totalx2Format));
ws.addCell(new Label(3, 3, "数量(张)",totalx2Format));
ws.addCell(new Label(4, 3, "金额(元)",totalx2Format));
ws.addCell(new Label(5, 3, "数量(张)",totalx2Format));
ws.addCell(new Label(6, 3, "金额(元)",totalx2Format));
ws.addCell(new Label(7, 3, "数量(张)",totalx2Format));
ws.addCell(new Label(8, 3, "金额(元)",totalx2Format));
ws.addCell(new Label(9, 3, "数量(张)",totalx2Format));
ws.addCell(new Label(10, 3, "金额(元)",totalx2Format));
ws.addCell(new Label(11, 3, "数量(张)",totalx2Format));
ws.addCell(new Label(12, 3, "金额(元)",totalx2Format));
ws.mergeCells(0, 1, 0, 3); //合并单元格,参数格式(开始列,开始行,结束列,结束行)
ws.mergeCells(1, 1, 6, 1);
ws.mergeCells(7, 1, 12, 1);
ws.mergeCells(13, 1, 14, 1);
ws.mergeCells(1, 2, 2, 2);
ws.mergeCells(3, 2, 4, 2);
ws.mergeCells(5, 2, 6, 2);
ws.mergeCells(7, 2, 8, 2);
ws.mergeCells(9, 2, 10, 2);
ws.mergeCells(11, 2, 12, 2);
ws.mergeCells(13, 2, 13, 3);
ws.mergeCells(14, 2, 14, 3);
ws.mergeCells(15, 1, 15, 3);
ws.setColumnView(0, 15);
ws.setColumnView(1, 10);
ws.setColumnView(2, 10);
ws.setColumnView(3, 10);
ws.setColumnView(4, 10);
ws.setColumnView(5, 10);
ws.setColumnView(6, 10);
ws.setColumnView(7, 10);
ws.setColumnView(8, 10);
ws.setColumnView(9, 10);
ws.setColumnView(10, 10);
ws.setColumnView(11, 10);
ws.setColumnView(12, 10);
ws.setColumnView(13, 10);
ws.setColumnView(14, 10);
ws.setColumnView(15, 15);
beginDate = request.getParameter("beginDate");
endDate = request.getParameter("endDate");
orgname = request.getParameter("orgname");
data = createQuery( beginDate, endDate, orgname);
for (int i = 0; i < data.size(); i++) {
DynaBean dynaBean = (DynaBean)data.get(i);
String orgname = StringUtil.parseNull( dynaBean.get("orgname")) ;
String c_amount20 = StringUtil.parseNull( dynaBean.get("c_amount20"));
String c_paymoney20 = StringUtil.parseNumber( dynaBean.get("c_paymoney20"));
String c_amount25 = StringUtil.parseNull( dynaBean.get("c_amount25"));
String c_paymoney25 = StringUtil.parseNumber( dynaBean.get("c_paymoney25"));
String c_amount50 = StringUtil.parseNull( dynaBean.get("c_amount50"));
String c_paymoney50 = StringUtil.parseNumber( dynaBean.get("c_paymoney50"));
String v_amount30 = StringUtil.parseNull( dynaBean.get("v_amount30"));
String v_paymoney30 = StringUtil.parseNumber( dynaBean.get("v_paymoney30"));
String v_amount50 = StringUtil.parseNull( dynaBean.get("v_amount50"));
String v_paymoney50 = StringUtil.parseNumber( dynaBean.get("v_paymoney50"));
String v_amount100 = StringUtil.parseNull( dynaBean.get("v_amount100"));
String v_paymoney100 = StringUtil.parseNumber( dynaBean.get("v_paymoney100"));
String c_amountonline = StringUtil.parseNull( dynaBean.get("c_amountonline"));
String c_paymoneyonline = StringUtil.parseNumber( dynaBean.get("c_paymoneyonline"));
String totle =
StringUtil.parseNumber(Double.parseDouble(c_paymoney20)
+ Double.parseDouble(c_paymoney25)
+ Double.parseDouble(c_paymoney50)
+ Double.parseDouble(v_paymoney30)
+ Double.parseDouble(v_paymoney50)
+ Double.parseDouble(v_paymoney100)
+ Double.parseDouble(c_paymoneyonline));
WritableCellFormat numberFormat = new WritableCellFormat();
numberFormat.setAlignment(Alignment.RIGHT);
ws.addCell(new Label(0, i + 4, orgname));
ws.addCell(new Label(1, i + 4, c_amount20,numberFormat));
ws.addCell(new Label(2, i + 4, c_paymoney20,numberFormat));
ws.addCell(new Label(3, i + 4, c_amount25,numberFormat));
ws.addCell(new Label(4, i + 4, c_paymoney25,numberFormat));
ws.addCell(new Label(5, i + 4, c_amount50,numberFormat));
ws.addCell(new Label(6, i + 4, c_paymoney50,numberFormat));
ws.addCell(new Label(7, i + 4, v_amount30,numberFormat));
ws.addCell(new Label(8, i + 4, v_paymoney30,numberFormat));
ws.addCell(new Label(9, i + 4, v_amount50,numberFormat));
ws.addCell(new Label(10, i + 4,v_paymoney50,numberFormat));
ws.addCell(new Label(11, i + 4,v_amount100,numberFormat));
ws.addCell(new Label(12, i + 4,v_paymoney100,numberFormat));
ws.addCell(new Label(13, i + 4,c_amountonline,numberFormat));
ws.addCell(new Label(14, i + 4,c_paymoneyonline,numberFormat));
ws.addCell(new Label(15, i + 4,totle,numberFormat));
}
wwb.write();
wwb.close();
}
分享到:
相关推荐
struts2导出excel java 导出excel: JXL_excel: 可以直接在elipse下运行的例子 可以直接导出excel文件(包含所需的jar包) CSharpJExcel: 是JXL的官方下载的 包括详细的文档 和jar包
poi struts2 导出Excel 用jdbc连的sql server2000 非常简单 一看就能明白怎么个回事 就一张表 3个字段 适合第一次用poi的朋友
struts2 导出 excel 可以很好的移植到你的项目中去!
struts2实现excel导出struts2实现excel导出struts2实现excel导出struts2实现excel导出
NULL 博文链接:https://wasw100.iteye.com/blog/576494
运用最简单易懂的方式写了导出的步骤,剔除了样式,更直接易懂,加入了POI必须的jar包,还加入了HSSF的帮助文档,很实用的
Struts1.2导出Excel表完美版
struts2中利用poi导出excel的简单例子
利用struts2和poi把数据导出到excel
整合struts2 ssh导出excel,绝对可以用。
struts1.2+extjs+导出excel项目 struts1.2+extjs+导出excel项目
主要是利用struts2导出excel,格式良好,jar包已添加,可以直接导入运行,有什么问题请联系我
使用JSP、Struts2和jquery实现简单查询,分页,导出到Excel并保存到本地计算机。(数据库相关内容在webroot下db文件夹内)
此文档提供全面的poi导出excel,对于有这方面需要的朋友有很大的帮助。
Struts2+Excel导出Demo,测试可用带全部运行所需的JAR包
本文档详细介绍了struts2整合apache的jxl导入导出excel表格的方法。包括代码,可以直接使用。
web中使用POI导入导出EXCEL文件的例子 struts1.x的例子,struts2.x可以参考自己修改 1.action的写法 import java.io.*; import java.sql.*; import java.util.ArrayList; import javax.servlet....
poi-3.10-FINAL-20140208.jar,jxls-core-1.0.5.jar,poi-ooxml-3.10-FINAL-20140208.jar,commons-digester-2.1.jar,commons-jexl-2.1.1.jar 博文地址:http://blog.csdn.net/richerg85/article/details/42459471
利用纯struts2.0+poi插件 实现导出excel
Struts2文件流方式导出下载excel、Txt、image图片,直接返回给浏览器提示下载,不生成临时文件,直接保存在客户端