POI处理超过65536条记录

16 篇文章 0 订阅

03格式的excel文件(.xls)最多只支持65536行,所以当需要处理的数据超过65536时,便不能使用HSSFWorkbook了,即不能用03格式的excel了

07格式的excel文件(.xlsx)对应的方法是:XSSFWorkbook

先读取一个表头:

		SXSSFWorkbook wb2 = new SXSSFWorkbook(6000);
		File file = new File("C:/Users/DLTB/Desktop/1.xlsx");  
//		File file = new File( request.getSession().getServletContext().getRealPath("/")+"/resources/model/logmodel.xlsx");  
		XSSFWorkbook x = null;
		try {
			InputStream is = new FileInputStream(file);
			x = new XSSFWorkbook(new BufferedInputStream(is));
			wb2 = new SXSSFWorkbook(x,6000);
		} catch (Exception e) {
			e.printStackTrace();
		} 
	

读取该文件的第一张表:

Sheet sheet = wb.getSheetAt(0);

<span style="white-space:pre">	</span>List<Log> logList = logMapper.getLogList();//写入的数据(随便改)
		for (int rownum = 0; rownum < logList.size(); rownum++) {
			Log log = logList.get(rownum);
			int i = 0;
			Row row1 = sheet.createRow(rownum + 3);
			row1.createCell(i++).setCellValue(log.getCol1());/<span style="font-family: Arial, Helvetica, sans-serif;">/写入的数据(随便改)</span>
			row1.createCell(i++).setCellValue(log.getCol2());//写入的数据(随便改)
		
	}
浏览器生成下载链接:

<span style="white-space:pre">	</span>String fileName = "操作记录";
		fileName += ".xlsx";
		response.setContentType("application/vnd.ms-excel");
		try {
			response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
			OutputStream ouputStream;
			ouputStream = response.getOutputStream();
			wb.write(ouputStream);
			ouputStream.flush();
			ouputStream.close();
		} catch (IOException e) {
			e.printStackTrace();
		}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值