大数据导出(最高可达2.6624亿)


SXSSFWorkbook wb = new SXSSFWorkbook(15);// 构造一个空的工作薄,并指定一个窗口访问
        Sheet sh = wb.createSheet();
        // 居中
        // 宽度设置
        sh.setColumnWidth(0, 25 * 256);
        sh.setColumnWidth(1, 35 * 256);
        sh.setColumnWidth(2, 20 * 256);
        sh.setColumnWidth(3, 20 * 256);
        sh.setColumnWidth(4, 20 * 256);
        sh.setColumnWidth(5, 20 * 256);
        sh.setColumnWidth(6, 20 * 256);
        sh.setColumnWidth(7, 20 * 256);
        sh.setColumnWidth(8, 20 * 256);
        sh.setColumnWidth(9, 20 * 256);
        sh.setColumnWidth(10, 20 * 256);
        // 高度设置
        sh.createRow(0).setHeightInPoints(20);
        sh.createRow(1).setHeightInPoints(20);
        sh.createRow(2).setHeightInPoints(20);
        sh.createRow(3).setHeightInPoints(20);
        sh.createRow(4).setHeightInPoints(20);
        sh.createRow(5).setHeightInPoints(20);
        sh.createRow(6).setHeightInPoints(20);
        sh.createRow(7).setHeightInPoints(20);
        sh.createRow(8).setHeightInPoints(20);
        sh.createRow(9).setHeightInPoints(20);
        sh.createRow(10).setHeightInPoints(20);

        Row row = sh.createRow(0);

        // ---------------------创建列设置列明-----------------------------
        Cell cel0 = row.createCell(0);
        cel0.setCellValue("流水号");
        Cell cel1 = row.createCell(1);
        cel1.setCellValue("日期");
        Cell cel2 = row.createCell(2);
        cel2.setCellValue("玩家ID");
        Cell cel3 = row.createCell(3);
        cel3.setCellValue("桌号");
        Cell cel4 = row.createCell(4);
        cel4.setCellValue("游戏");
        Cell cel5 = row.createCell(5);
        cel5.setCellValue("种类");
        Cell cel6 = row.createCell(6);
        cel6.setCellValue("支付渠道");
        Cell cel7 = row.createCell(7);
        cel7.setCellValue("现金");
        Cell cel8 = row.createCell(8);
        cel8.setCellValue("派币");
        Cell cel9 = row.createCell(9);
        cel9.setCellValue("砖石");
        Cell cel10 = row.createCell(10);
        cel10.setCellValue("状态");

        // ------------------定义表头----------------------------------------
        List<Transaction> list = new ArrayList<Transaction>();
        int page_size = 10000;// 数据库中存储的数据行数
        // 添加条件
        String curMerId = session.get("merchantId");
        if (vo.typeList != null && vo.typeList.removeAll(Collections.singleton(null))) {
            vo.typeList = null;
        }
        if (vo.merchantId == 0)
            vo.merchantId = Long.parseLong(curMerId);
        int list_count = Transaction.findList(vo).totalCount;// 数据的总数量
        // -----------------判断需要查询的次数----------------------------------------
        int export_times = list_count % page_size > 0 ? list_count / page_size
            + 1 : list_count / page_size;
        for (int j = 0; j < export_times; j++) {
            // 查询所有的数据
            vo.pageNo = j + 1;// 单次查询的页码
            vo.pageSize = page_size;// 单次查询的总条数
            list = Transaction.findListTwo(vo, list_count).items;// 单词查询的数据类容集合
            int len = list.size() < page_size ? list.size() : page_size;// 判断查询的数据长度
            for (int i = 0; i < len; i++) {
                Row row_value = sh.createRow(j * page_size + i + 1);// 代表行

                // ---------向每一行中添加列内容--------
                Cell cel0_value = row_value.createCell(0);
                cel0_value.setCellValue(String.valueOf(list.get(i).id));// 流水号
                Cell cel1_value = row_value.createCell(1);
                cel1_value.setCellValue(list.get(i).createTime.toString());// 日期
                Cell cel2_value = row_value.createCell(2);
                cel2_value.setCellValue(list.get(i).playerId);// 玩家ID
                Cell cel3_value = row_value.createCell(3);
                cel3_value.setCellValue(list.get(i).deskId);// 桌号
                Cell cel4_value = row_value.createCell(4);
                if (list.get(i).game != null) {
                    cel4_value.setCellValue(list.get(i).game.name);// 游戏
                } else {
                    cel4_value.setCellValue("空");// 游戏
                }
                Cell cel5_value = row_value.createCell(5);
                cel5_value.setCellValue(list.get(i).type.title);// 种类
                Cell cel6_value = row_value.createCell(6);
                if (list.get(i).channel == null)
                    cel6_value.setCellValue("null");// 支付渠道
                else
                    cel6_value.setCellValue(list.get(i).channel.title);// 支付渠道

                Cell cel7_value = row_value.createCell(7);
                cel7_value.setCellValue(list.get(i).money);// 现金
                Cell cel8_value = row_value.createCell(8);
                cel8_value.setCellValue(list.get(i).coin);// 派币
                Cell cel9_value = row_value.createCell(9);
                cel9_value.setCellValue(list.get(i).points);// 砖石
                Cell cel10_value = row_value.createCell(10);
                if (list.get(i).status != null) {
                    cel10_value.setCellValue(list.get(i).status.title);// 状态
                } else {
                    cel10_value.setCellValue("null");// 状态
                }
            }
            list.clear();// 清除list
        }
        response.current().contentType="octets/stream";
        String filename = "流水数据-" + new DateTime().now().toString("yyyyMMddHHmmss") + ".xls";
        response.current().setHeader("Content-Disposition","attachment;filename="+filename);
        ByteArrayOutputStream baout = new ByteArrayOutputStream();
        wb.write(baout);
        ByteArrayInputStream bais = new ByteArrayInputStream(baout.toByteArray());
        byte[] bs = IO.readContent(bais);
        response.out.write(bs);
        baout.close();
        response.out.flush();
        response.out.close();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值