没有合适的资源?快使用搜索试试~ 我知道了~
將大量數據下載至Excel
3星 · 超过75%的资源 需积分: 3 8 下载量 19 浏览量
2014-07-03
15:25:05
上传
评论
收藏 14KB TXT 举报
温馨提示
试读
7页
將大量數據下載至Excel,SXSSFWorkbook避免內存溢出
资源推荐
资源详情
资源评论
將大量數據下載至Excel,循環調用service釋放內存并用SXSSFWorkbook避免內存溢出。
/**
* 画面结果导出按钮操作
*/
public void exportResult() throws Exception {
// Execl生成
XSSFWorkbook workBook = new XSSFWorkbook();
HttpServletRequest request = ServletActionContext.getRequest();
String realPath = request.getSession().getServletContext()
.getRealPath("/");
OPCPackage opc = OPCPackage.open(realPath
+ PurchaseInvoice_Constants.PRODUCTLISTPATH);
workBook = new XSSFWorkbook(opc);
// 内存中保留 10000 条数据,以免内存溢出,其余写入硬盘
SXSSFWorkbook sworkBook = new SXSSFWorkbook(workBook, 10000);
Sheet nowSheet = sworkBook.getSheetAt(0);
CellStyle style = sworkBook.createCellStyle();
style.setBorderBottom(XSSFCellStyle.BORDER_THIN);
style.setBorderLeft(XSSFCellStyle.BORDER_THIN);
style.setBorderRight(XSSFCellStyle.BORDER_THIN);
style.setBorderTop(XSSFCellStyle.BORDER_THIN);
// 需要导出的数据取得
int count = productListService.getExportResultListCount(searchDto);
int sheetPage = 0;
/**
* 画面结果导出按钮操作
*/
public void exportResult() throws Exception {
// Execl生成
XSSFWorkbook workBook = new XSSFWorkbook();
HttpServletRequest request = ServletActionContext.getRequest();
String realPath = request.getSession().getServletContext()
.getRealPath("/");
OPCPackage opc = OPCPackage.open(realPath
+ PurchaseInvoice_Constants.PRODUCTLISTPATH);
workBook = new XSSFWorkbook(opc);
// 内存中保留 10000 条数据,以免内存溢出,其余写入硬盘
SXSSFWorkbook sworkBook = new SXSSFWorkbook(workBook, 10000);
Sheet nowSheet = sworkBook.getSheetAt(0);
CellStyle style = sworkBook.createCellStyle();
style.setBorderBottom(XSSFCellStyle.BORDER_THIN);
style.setBorderLeft(XSSFCellStyle.BORDER_THIN);
style.setBorderRight(XSSFCellStyle.BORDER_THIN);
style.setBorderTop(XSSFCellStyle.BORDER_THIN);
// 需要导出的数据取得
int count = productListService.getExportResultListCount(searchDto);
int sheetPage = 0;
if(count % 50000 == 0){
sheetPage = count / 50000;
}else {
sheetPage = count / 50000 + 1;
}
for (int sheet=0;sheet<sheetPage;sheet++) {
searchDto.setStartPoint(sheet*50000);
searchDto.setEndPoint(50000);
List<ProductListExportDto> exportList = productListService.getExportResultList(searchDto);
Row row = null;
Cell cell = null;
int i = 0;
for (ProductListExportDto arg : exportList) {
row = nowSheet.createRow(i+7+sheet*50000);
// No
cell = row.createCell(0);
cell.setCellValue(String.valueOf(i+1));
cell.setCellStyle(style);
// 供应商简称
cell = row.createCell(1);
cell.setCellValue(arg.getSuppliershortName());
cell.setCellStyle(style);
sheetPage = count / 50000;
}else {
sheetPage = count / 50000 + 1;
}
for (int sheet=0;sheet<sheetPage;sheet++) {
searchDto.setStartPoint(sheet*50000);
searchDto.setEndPoint(50000);
List<ProductListExportDto> exportList = productListService.getExportResultList(searchDto);
Row row = null;
Cell cell = null;
int i = 0;
for (ProductListExportDto arg : exportList) {
row = nowSheet.createRow(i+7+sheet*50000);
// No
cell = row.createCell(0);
cell.setCellValue(String.valueOf(i+1));
cell.setCellStyle(style);
// 供应商简称
cell = row.createCell(1);
cell.setCellValue(arg.getSuppliershortName());
cell.setCellStyle(style);
剩余6页未读,继续阅读
资源评论
- 陈东青向前2014-07-05好资源,多谢分享。
JYOKETSU
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功