加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

基于 angularjs+jfinal 的 excel文件导出

发布时间:2020-12-17 10:04:46 所属栏目:安全 来源:网络整理
导读:使用的jar包 为: poi 我的下载分享里有。 Js: $scope.expExcel = function() { var start=$("#start").val(); var end =$("#end").val(); var state =$scope.searchInfo.state; var name =$scope.searchInfo.name; window.open("withdraw/expExcel?state="

使用的jar包 为: poi 我的下载分享里有。

Js: 
$scope.expExcel = function() {
    var start=$("#start").val();
    var end    =$("#end").val();
    var state =$scope.searchInfo.state;
    var name =$scope.searchInfo.name;
        
        window.open("withdraw/expExcel?state=" +state
                + "&start=" + start+ "&end=" + end+ "&name=" + name  );
        
    };

controller :
    @Clear
    public void expExcel() throws ParseException,IOException {
        SimpleDateFormat sb = new SimpleDateFormat("yyyy-MM-dd");
        String start = getPara("start");
        String end = getPara("end");
        Date startDate = null;
        Date endDate = null;
        if (StringUtils.isNotEmpty(start)) {
            startDate = sb.parse(start);
        }
        if (StringUtils.isNotEmpty(end)) {
            endDate = sb.parse(end);
        }
        // 获取导出集合
        List<WithdrawHistory> billList = WithdrawHistory.dao.getBillList(getPara("state"),getPara("name"),startDate,endDate);
        // 开始Excel导出
        String EXPORT_PATH = getSession().getServletContext().getRealPath("");
        System.out.println(" EXPORT_PATH:" + EXPORT_PATH);
        File file = new File(EXPORT_PATH + File.separator + "提现履历信息.xls");
        if (file.exists()) {
            file.delete();
        }

        // 工作簿
        HSSFWorkbook wb = new HSSFWorkbook();
        // 表单
        HSSFSheet sheet = wb.createSheet("提现履历");

        // 表头
        HSSFRow row = sheet.createRow(0);
        HSSFCell cell = row.createCell(0);
        cell.setCellValue("查询条件: ");
        cell = row.createCell(1);
        cell.setCellValue("统计期间(" + start + " ~ " + end + ")");
        cell = row.createCell(2);
        String userName = "无";
        if (StringUtils.isNotEmpty(getPara("name"))) {
            userName = getPara("name");
        }
        cell.setCellValue("用户名:" + userName);
        row = sheet.createRow(1);
        cell = row.createCell(0);
        cell.setCellValue("No.");
        cell = row.createCell(1);
        cell.setCellValue("姓名");
        cell = row.createCell(2);
        cell.setCellValue("开户行");
        cell = row.createCell(3);
        cell.setCellValue("银行账号");
        cell = row.createCell(4);
        cell.setCellValue("转账凭证");
        cell = row.createCell(5);
        cell.setCellValue("提现金额(元)");
        cell = row.createCell(6);
        cell.setCellValue("交易状态");
        cell = row.createCell(7);
        cell.setCellValue("转账时间");
        cell = row.createCell(8);
        cell.setCellValue("操作人员");
        int i = 1;
        for (WithdrawHistory billBo : billList) {

            row = sheet.createRow(i + 1);

            cell = row.createCell(0);
            cell.setCellType(HSSFCell.CELL_TYPE_STRING);
            cell.setCellValue(Integer.toString(i));

            cell = row.createCell(1);
            cell.setCellType(HSSFCell.CELL_TYPE_STRING);
            cell.setCellValue(billBo.getStr("name"));

            cell = row.createCell(2);
            cell.setCellType(HSSFCell.CELL_TYPE_STRING);
            cell.setCellValue(billBo.getStr("bank"));

            cell = row.createCell(3);
            cell.setCellType(HSSFCell.CELL_TYPE_STRING);
            cell.setCellValue(billBo.getStr("account"));

            cell = row.createCell(4);
            cell.setCellType(HSSFCell.CELL_TYPE_STRING);
            cell.setCellValue(billBo.getStr("voucher"));

            cell = row.createCell(5);
            cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
            cell.setCellValue(billBo.getBigDecimal("rmb_num").doubleValue());

            cell = row.createCell(6);
            cell.setCellType(HSSFCell.CELL_TYPE_STRING);
            cell.setCellValue(billBo.getStr("state_str"));

            cell = row.createCell(7);
            cell.setCellType(HSSFCell.CELL_TYPE_STRING);
            SimpleDateFormat sft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date transferTime = billBo.getDate("transfer_time");
            String t2 = "";
            if (transferTime != null) {
                t2 = sft.format(transferTime);
            }

            cell.setCellValue(t2);
            cell = row.createCell(8);
            cell.setCellType(HSSFCell.CELL_TYPE_STRING);
            cell.setCellValue(billBo.getStr("operator"));
            i++;
        }
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(file);
            wb.write(fos);
            fos.flush();
        } finally {
            if (fos != null) {
                fos.close();
            }
        }
        render(new FileRender(file,file.getName()));
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读