1
chendy 2020-06-08 18:53:14 +08:00
有 write (或者叫 writeTo ?)方法,为啥还要写临时文件
|
2
luckylo 2020-06-09 06:58:33 +08:00 via Android
可以的。如楼上所言。顺便提一句,当心内存问题
|
3
fxxwor99LVHTing 2020-06-09 08:33:23 +08:00
直接把字节数据写到 response 里面
|
4
xuanbg 2020-06-09 08:52:55 +08:00
为什么要生成临时文件?直接
``` OutputStream stream = new FileOutputStream(file); workbook.write(stream); ``` |
5
lqw3030 2020-06-09 08:56:34 +08:00
当然可以,但是考虑到内存占用,SXSSFWorkbook 还特地提供了类似"滑动窗口"的机制
|
6
goldpumpkin OP |
7
goldpumpkin OP @fxxwor99LVHTing
@xuanbg 谢谢回复。其实我想要的是增量输出到 outputstream 里面,我试了一下,不得行。 ``` try { ServletResponse responseAsync = asyncContext.getResponse(); responseAsync.setCharacterEncoding("utf-8"); List<List<String>> row = Arrays.asList(CollUtil.newArrayList("订单号", "渠道", "下班时间", "加班时长", "餐补", "车补次数", "车补", "总计")); ExcelWriter excelWriter = ExcelUtil.getBigWriter(); excelWriter.write(row); excelWriter.flush(responseAsync.getOutputStream()); responseAsync.getOutputStream().flush(); for (int i = 0; i < 10; i++) { excelWriter.write(row); excelWriter.flush(responseAsync.getOutputStream()); Thread.sleep(2000); } responseAsync.getOutputStream().flush(); } catch (Exception e) { } ``` |
8
wiix 2020-06-09 12:23:51 +08:00
|
9
lqw3030 2020-06-09 13:36:50 +08:00
|
10
goldpumpkin OP |
11
xinQing 2020-06-09 18:19:23 +08:00
数据分批次从数据库查出,写入 response
|