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的第一列需要写保 ...
随机推荐
- C++扬帆远航——12(抓小偷)
/* * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:zhaoxiaotou.cpp * 作者:常轩 * 微信公众号: ...
- oa办公系统快速开发工具,助力企业优化升级
随着互联网的快速发展.信息化 IT 技术的不断进步.移动互联新技术的兴起,不管是大的集团企业还是中小型企业,纸质化的办公模式已不能满足现有需求,构建oa平台,为员工提供高效的办公环境尤其重要. 我们先 ...
- Ⅱ:python入门
一.编程语言介绍 编程语言的分类: 机器语言 汇编语言 高级语言(编译型.解释型号) 总结: 执行效率:机器语言>汇编语言>高级语言(编译型>解释型) 开发效率:机器语言<汇编 ...
- react-intl 实现 React 国际化多语言
效果预览 React Intl 国际化步骤 创建国际化资源文件 根据语言获取国际化资源 引入 react-intl 的 local data 创建 LocaleProvider 国际化上下文组件 创建 ...
- IntelliJ IDEA神器使用技巧
说明:详情请参考慕课网课程:IntelliJ IDEA神器使用技巧:http://www.imooc.com/learn/924(感谢课程作者:闪电侠) 推荐: 1. 课程老师(闪电侠)IDEA快捷键 ...
- Web安全相关(一):CSRF/XSRF(跨站请求伪造)和XSS(跨站脚本)
XSS(Cross Site Script):跨站脚本,也就是javascript脚本注入,一般在站点中的富文本框,里面发表文章,留言等表单,这种表单一般是写入数据库,然后再某个页面打开. 防御: 1 ...
- vue的插件使用
插件通常是为Vue添加全局功能,vue的官网介绍了5中添加插件的方法. vue的插件有个公开方法install.第一个参数是Vue构造器,第二个参数是一个可选的选项对象. 在plugin.js中可以这 ...
- 【字节校招】【实习】【内推】字节跳动春招(校招或实习均可)以及日常实习内推ing
本人是年前刚刚入职抖音的应届生,职业认证还未来的级更改,但是这些都不重要.重要的是我们不能错过优秀的你~ 字节跳动的相关福利我就不介绍了,技术实习生是400/天,房补是1500/月,三餐免费,下午茶, ...
- SpringBoot入门系列(五)Thymeleaf的常用标签和用法
前面介绍了Spring Boot 中的整合Thymeleaf .不清楚的朋友可以看看之前的文章:https://www.cnblogs.com/zhangweizhong/category/16577 ...
- 手把手教你用Abp vnext构建API接口服务
ABP是一个开源应用程序框架,该项目是ASP.NET Boilerplate Web应用程序框架的下一代,专注于基于ASP.NET Core的Web应用程序开发,也支持开发控制台应用程序. 官方网站: ...