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

[java] view plain copy print?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("状态"); // ------------------定义表头---------------------------------------- Listlist = new ArrayList();

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();

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容