excel导出功能
/*
* 导出 add by faby on 20180918
*/
public void export(){
HttpServletResponse response=ServletActionContext.getResponse();
HttpServletRequest request=ServletActionContext.getRequest();
ActionContext.initialize(ServletActionContext.getRequest(),ServletActionContext.getResponse());
formmail0001 = formService.getFormData("mail0001");
acLnAutoSend = new AcLnAutoSend();
getFormValue(formmail0001);
setObjValue(formmail0001, acLnAutoSend);
acLnAutoSendList = (List) acLnAutoSendBo.findAll(acLnAutoSend);
HSSFWorkbook wb = new HSSFWorkbook(); //创建一个excel文件
HSSFSheet sheet = wb.createSheet("sheet1"); //创建table工作薄
HSSFCellStyle style1 = wb.createCellStyle(); //新建单元格样式
style1.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 水平居中
style1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中
//画出页面单元格表头
HSSFRow row;
HSSFCell cell;
//第一行------------------------------------------------------------------------
row = sheet.createRow(0);
//sheet.addMergedRegion(new CellRangeAddress(0,0,0,0));//控制合并单元格
cell = row.createCell(0);
cell.setCellValue("日期");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,1,1));
cell = row.createCell(1);
cell.setCellValue("存入款");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,2,2));
cell = row.createCell(2);
cell.setCellValue("提取款");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,3,3));
cell = row.createCell(3);
cell.setCellValue("累计净存入金额");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,4,4));
cell = row.createCell(4);
cell.setCellValue("备付金余额");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,5,5));
cell = row.createCell(5);
cell.setCellValue("放款金额");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(0,0,0,13));
cell = row.createCell(6);
cell.setCellValue("还款本金金额");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(0,0,14,18));
cell = row.createCell(7);
cell.setCellValue("当日余额增加");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(0,0,19,23));
cell = row.createCell(8);
cell.setCellValue("累计余额");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(0,0,24,28));
cell = row.createCell(9);
cell.setCellValue("还款利息");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(0,0,29,30));
cell = row.createCell(10);
cell.setCellValue("还款罚息");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(0,0,31,32));
cell = row.createCell(11);
cell.setCellValue("应收收益");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,1,6,8));
cell = row.createCell(12);
cell.setCellValue("实收收益");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,1,9,10));
cell = row.createCell(13);
cell.setCellValue("累计收益");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,11,11));
cell = row.createCell(14);
cell.setCellValue("累计客户数");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,12,12));
cell = row.createCell(15);
cell.setCellValue("客户平均金额");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,13,13));
cell = row.createCell(16);
cell.setCellValue("借据数");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,14,14));
cell = row.createCell(17);
cell.setCellValue("借据平均金额");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,15,15));
cell = row.createCell(18);
cell.setCellValue("加权平均利率");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,16,16));
cell = row.createCell(19);
cell.setCellValue("累计客户数");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,17,17));
cell = row.createCell(20);
cell.setCellValue("客户平均金额");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,18,18));
cell = row.createCell(21);
cell.setCellValue("借据数");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,19,19));
cell = row.createCell(22);
cell.setCellValue("借据平均金额");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,20,20));
cell = row.createCell(23);
cell.setCellValue("加权平均利率");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,21,21));
cell = row.createCell(24);
cell.setCellValue("当日已结清金额");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,22,22));
cell = row.createCell(25);
cell.setCellValue("累计结清金额");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,23,23));
cell = row.createCell(26);
cell.setCellValue("加权平均久期(天)");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,24,24));
cell = row.createCell(27);
cell.setCellValue("加权平均利率");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,25,25));
cell = row.createCell(28);
cell.setCellValue("累计收益");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,26,26));
cell = row.createCell(29);
cell.setCellValue("逾期金额");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,27,27));
cell = row.createCell(30);
cell.setCellValue("加权平均利率");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,28,28));
cell = row.createCell(31);
cell.setCellValue("不良借据金额");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,29,29));
cell = row.createCell(32);
cell.setCellValue("不良率");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,30,30));
cell = row.createCell(33);
cell.setCellValue("还款金额");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,31,31));
cell = row.createCell(34);
cell.setCellValue("累计客户数(结清)");
cell.setCellStyle(style1);
//sheet.addMergedRegion(new CellRangeAddress(1,2,32,32));
cell = row.createCell(35);
cell.setCellValue("累计笔数(结清)");
cell.setCellStyle(style1);
cell = row.createCell(36);
cell.setCellValue("新增笔数");
cell.setCellStyle(style1);
cell = row.createCell(37);
cell.setCellValue("新增笔数(结清)");
cell.setCellStyle(style1);
cell = row.createCell(38);
cell.setCellValue("新增笔数(未结清)");
cell.setCellStyle(style1);
cell = row.createCell(39);
cell.setCellValue("新增平均期数");
cell.setCellStyle(style1);
String [][] array = findAll2();
for(int i = 0; i < array.length; i++) {
row = sheet.createRow(i+1);//创建表格行
for(int j = 0; j < array[i].length; j++) {
cell = row.createCell(j);//根据表格行创建单元格
if(j==0) {//日期 和 xx率 不做千分位
cell.setCellValue(array[i][j]);
} else {
cell.setCellValue(fmtMicrometer(array[i][j]));
}
}
}
Map<String,String> sysPathMap =(Map<String,String>)MBaseCache.getCache().getBeanCache(CachecodeUtil.SYS_PATH_STR, CachecodeUtil.SYS_PATH);
//String tmppath = sysPathMap.get("040");
//String tmppath = "C:\\Users\\13671\\Downloads";
//String tmppath="D:\\home";
String fileName = "Daily";
OutputStream out =null;
try {
File file =new File(fileName);
if (!file .exists() && !file .isDirectory())
{
file.mkdir();
}
response.setContentType("application/xls;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xls");//导出的格式及默认本地浏览器
out = response.getOutputStream();
wb.write(out);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
wb.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
//遍历查询出来的数据
private String[][] findAll2() {
String[][] array = new String[acLnAutoSendList.size()][40];
for(int i=0;i<acLnAutoSendList.size();i++) {
array[i][0]= ((AcLnAutoSend) acLnAutoSendList.get(i)).getABatchDate()+"";
array[i][1] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getADepositMoney()+"";
array[i][2] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getAExtractMoney()+"";
array[i][3] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getASumNetDepositMoney()+"";
array[i][4] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getAReserveBalance()+"";
array[i][5] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getALoanAmt()+"";
array[i][6] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getARepayPrincipalAmt()+"";
array[i][7] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getATheDayBalanceAdd()+"";
array[i][8] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getASumBalance()+"";
array[i][9] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getARepayInterest()+"";
array[i][10] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getARepayPenaltyInterest()+"";
array[i][11] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getAIncomeReceivable()+"";
array[i][12] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getARealIncome()+"";
array[i][13] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getASumIncome()+"";
array[i][14] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getBCountCustNbr()+"";
array[i][15] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getBCustAvgAmt()+"";
array[i][16] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getBReceiptNbr()+"";
array[i][17] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getBReceiptAvgAmt()+"";
array[i][18] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getBAvggInterestRate()+"";
array[i][19] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getCCountCustNbr()+"";
array[i][20] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getCCustAvgAmt()+"";
array[i][21] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getCReceiptNbr()+"";
array[i][22] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getCReceiptAvgAmt()+"";
array[i][23] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getCAvggInterestRate()+"";
array[i][24] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getDTheDaySettledAmt()+"";
array[i][25] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getDSumSettledAmt()+"";
array[i][26] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getDAvggDuration()+"";
array[i][27] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getDAvggInterestRate()+"";
array[i][28] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getDSumIncome()+"";
array[i][29] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getEOverdueAmt()+"";
array[i][30] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getEOverdueRate()+"";
array[i][31] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getFBadAmt()+"";
array[i][32] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getFBadRate()+"";
array[i][33] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getGRepayAmt()+"";
array[i][34] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getGCountCustNbr()+"";
array[i][35] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getGCount()+"";
array[i][36] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getGNewCount()+"";
array[i][37] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getGNewCountSettle()+"";
array[i][38] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getGNewCountUnclear()+"";
array[i][39] = ((AcLnAutoSend) acLnAutoSendList.get(i)).getGNewAvgTerm()+"";
}
return array;
}
/**
* 格式化数字为千分位显示;
* @param 要格式化的数字;
* @return
*/
public static String fmtMicrometer(String text)
{
DecimalFormat df = null;
if(text.indexOf(".") > 0)
{
if(text.length() - text.indexOf(".")-1 == 0)
{
df = new DecimalFormat("###,##0.");
}else if(text.length() - text.indexOf(".")-1 == 1)
{
df = new DecimalFormat("###,##0.0");
}else
{
df = new DecimalFormat("###,##0.00");
}
}else
{
df = new DecimalFormat("###,##0");
}
double number = 0.0;
try {
number = Double.parseDouble(text);
} catch (Exception e) {
number = 0.0;
}
return df.format(number);
}
excel导出功能的更多相关文章
- Atitit.excel导出 功能解决方案 php java C#.net版总集合.doc
Atitit.excel导出 功能解决方案 php java C#.net版总集合.docx 1.1. Excel的保存格式office2003 office2007/2010格式1 1.2. 类库选 ...
- 用SpringMvc实现Excel导出功能
以前只知道用poi导出Excel,最近用了SpringMvc的Excel导出功能,结合jxl和poi实现,的确比只用Poi好,两种实现方式如下: 一.结合jxl实现: 1.引入jxl的所需jar包: ...
- 利用Aspose.Cells完成easyUI中DataGrid数据的Excel导出功能
我准备在项目中实现该功能之前,google发现大部分代码都是利用一般处理程序HttpHandler实现的服务器端数据的Excel导出,但是这样存在的问题是ashx读取的数据一般都是数据库中视图的数据, ...
- excel导出功能优化
先说说优化前,怎么做EXCEL导出功能的: 1. 先定义一个VO类,类中的字段按照EXCEL的顺序定义,并且该类只能用于EXCEL导出使用,不能随便修改. 2. 将查询到的结果集循环写入到这个VO类中 ...
- excel导出功能原型
本篇博客是记录自己实现的excel导出功能原型,下面我将简单介绍本原型: 这是我自制的窗体,有一个ListView和一个Button(导出)控件. 这是我在网上找到了使用exel需要引用的库. usi ...
- java利用EasyPoi实现Excel导出功能
easypoi功能如同名字easy,主打的功能就是容易,让一个没见接触过poi的人员 就可以方便的写出Excel导出,Excel模板导出,Excel导入,Word模板导出,通过简单的注解和模板 语言( ...
- asp.net excel导出功能
以下是我在项目开发中所做的关于Excel导出功能,不足之处还望大家指正,相互学习 protected void btn_Export_Click(object sender, EventArgs e) ...
- 使用NPOI实现简单的Excel导出功能
[1]NPOI是啥? NPOI是指构建在POI 3.x版本之上的一个程序,NPOI可以在没有安装Office的情况下对Word或Excel文档进行读写操作. POI是一个开源的Java读写Excel. ...
- Delphi实现带有格式的Excel导出功能
功能预览 运行预览 模板样式 存储返参 导出的Excel 2. 代码实现 //执行sql的函数 procedure TForm1.GetReportData(astrsql:string); var ...
- java(POI):基于模版的Excel导出功能,局部列写保护总结
需求描述: 1.导出的Excel中部分列包含有下拉列表,并没有尝试过用代码实现这种功能,个人感觉比较棘手,故采用了模版的形式,直接导出数据到已经创建好的Excel模版中 2.Excel的第一列需要写保 ...
随机推荐
- HTTP Continuation or non-HTTP traffic
发现一个 HTTP Continuation or non-HTTP traffic的数据包,之前没有碰到过.不懂其意义,一看长度,显示1460,与TCP segment of a reas ...
- NumPy的随机函数子库——numpy.random
NumPy的随机函数子库numpy.random 导入模块:import numpy as np 1.numpy.random.rand(d0,d1,...,dn) 生成一个shape为(d0,d1, ...
- 93-time模块
目录 time模块 一.time模块 1.1 时间戳 1.2 格式化时间 1.3 结构化时间 1.4 不同格式时间之间的转换 1.5 其它用法 time模块 一.time模块 import time ...
- Java大浮点数精度
BigDecimal 精度问题 BigDecimal舍入模式 ROUND_DOWN 向零舍入. 即1.55 变为 1.5 , -1.55 变为-1.5 ROUND_UP 向远离0的方向舍入 即 1.5 ...
- Web网页布局的主要方式
一.静态布局(static layout) 即传统Web设计,网页上的所有元素的尺寸一律使用px作为单位. 1.布局特点 不管浏览器尺寸具体是多少,网页布局始终按照最初写代码时的布局来显示.常规的pc ...
- Oracle批量插入有日期类型数据
例如现在有张表 id(number) startTime(date) name(varchar2) 1 2017-08-13 zhangsan 2 2017-08-14 zhangsan 需要批量 ...
- MATLAB神经网络(1)之R练习
)之R练习 将在MATLAB神经网络中学到的知识用R进行适当地重构,再写一遍,一方面可以加深理解和记忆,另一方面练习R,比较R和MATLAB的不同.如要在R中使用之前的数据,应首先在MATLAB中用w ...
- burpsuit之Spider、Scanner、Intruder模块
1.spider模块 1.spider模块介绍 被动爬网:(被动爬网获得的链接是手动爬网的时候返回页面的信息中分析发现超链接) 对于爬网的时候遇到HTML表单如何操作: 需要表单身份认证时如何操作(默 ...
- 每天都在用 Map,这些核心技术你知道吗?
本篇文章站在多线程并发安全角度,带你了解多线程并发使用 HashMap 将会引发的问题,深入学习 ConcurrentHashMap ,带你彻底掌握这些核心技术. 全文摘要: HashMap 核心技术 ...
- 如何使用Logstash
目录 一.什么是Logstash 二.如何安装 三.快速使用 四.Input输入插件 五.codec编码插件 六.filter过滤器插件 七.output输出插件 八.总结 一.什么是Logstash ...