/*
  * 导出 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导出功能的更多相关文章

  1. Atitit.excel导出 功能解决方案 php java C#.net版总集合.doc

    Atitit.excel导出 功能解决方案 php java C#.net版总集合.docx 1.1. Excel的保存格式office2003 office2007/2010格式1 1.2. 类库选 ...

  2. 用SpringMvc实现Excel导出功能

    以前只知道用poi导出Excel,最近用了SpringMvc的Excel导出功能,结合jxl和poi实现,的确比只用Poi好,两种实现方式如下: 一.结合jxl实现: 1.引入jxl的所需jar包: ...

  3. 利用Aspose.Cells完成easyUI中DataGrid数据的Excel导出功能

    我准备在项目中实现该功能之前,google发现大部分代码都是利用一般处理程序HttpHandler实现的服务器端数据的Excel导出,但是这样存在的问题是ashx读取的数据一般都是数据库中视图的数据, ...

  4. excel导出功能优化

    先说说优化前,怎么做EXCEL导出功能的: 1. 先定义一个VO类,类中的字段按照EXCEL的顺序定义,并且该类只能用于EXCEL导出使用,不能随便修改. 2. 将查询到的结果集循环写入到这个VO类中 ...

  5. excel导出功能原型

    本篇博客是记录自己实现的excel导出功能原型,下面我将简单介绍本原型: 这是我自制的窗体,有一个ListView和一个Button(导出)控件. 这是我在网上找到了使用exel需要引用的库. usi ...

  6. java利用EasyPoi实现Excel导出功能

    easypoi功能如同名字easy,主打的功能就是容易,让一个没见接触过poi的人员 就可以方便的写出Excel导出,Excel模板导出,Excel导入,Word模板导出,通过简单的注解和模板 语言( ...

  7. asp.net excel导出功能

    以下是我在项目开发中所做的关于Excel导出功能,不足之处还望大家指正,相互学习 protected void btn_Export_Click(object sender, EventArgs e) ...

  8. 使用NPOI实现简单的Excel导出功能

    [1]NPOI是啥? NPOI是指构建在POI 3.x版本之上的一个程序,NPOI可以在没有安装Office的情况下对Word或Excel文档进行读写操作. POI是一个开源的Java读写Excel. ...

  9. Delphi实现带有格式的Excel导出功能

    功能预览 运行预览 模板样式 存储返参 导出的Excel 2. 代码实现 //执行sql的函数 procedure TForm1.GetReportData(astrsql:string); var ...

  10. java(POI):基于模版的Excel导出功能,局部列写保护总结

    需求描述: 1.导出的Excel中部分列包含有下拉列表,并没有尝试过用代码实现这种功能,个人感觉比较棘手,故采用了模版的形式,直接导出数据到已经创建好的Excel模版中 2.Excel的第一列需要写保 ...

随机推荐

  1. AndroidManifest.xml文件详解

    本文为安全专家李洋的最新一篇专栏文章<AndroidManifest.xml文件详解>.AndroidManifest.xml是一个跟安全相关的配置文件,该配置文件是Android安全保障 ...

  2. PyGame学习笔记之壹

    新建窗口 代码 '''PyGame学习笔记之壹''' import pygame # 引入 PyGame 库 pygame.init() # PyGame 库初始化 screen = pygame.d ...

  3. 解决ionic2/ionic3轮播图切换页面或者点击过后不自动轮图

    我们在ionic2/ionic3开发的过程中会出现切换页面或者滑动切换轮播图出现轮播图不再轮播的情况,这其实需要一些配置. 首先在运用到轮播图的component中引入 import {ViewChi ...

  4. 使用HBuilder开发移动APP

    前言 HBuilder是DCloud(数字天堂)推出的一款支持HTML5的Web开发IDE.HBuilder的编写用到了Java.C.Web和Ruby.HBuilder本身主体是由Java编写,它基于 ...

  5. 1024程序员节最新福利之2018最全H5前端资料集

    前言 有好久没有写博客了,主要这段时间都沉迷学习无法自拔了,哈哈.自吹一波. 前两天不是1024节吗,所以就有很多福利出现了,当然每个人能都获得的信息都有所不同,这就是所谓的信息差.秉着好东西需要分享 ...

  6. JS 增删改查操作XML

    效果图: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...

  7. Css里的BFC

    一.BFC简介 BFC全称:Block Formatting Contexts (BFC,块级格式化上下文),就是 一个块级元素 的渲染显示规则 (可以把 BFC 理解为一个封闭的大箱子,,容器里面的 ...

  8. 前端每日实战:31# 视频演示如何利用 CSS 的动画原理,创作一个乒乓球对打动画

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/rvgLzK 可交互视频教程 此视频 ...

  9. php Rabbitmq扩展安装坑点

    pecl install amqp 出现 checking for amqp using pkg-config... configure: error: librabbitmq not found 这 ...

  10. (28)ASP.NET Core AutoMapper组件

    1.什么是AutoMapper? AutoMapper是一个对象-对象映射器.对象-对象映射通过将一种类型的输入对象转换为另一种类型的输出对象来工作.使AutoMapper变得有趣的是,它提供了一些有 ...