Jxls导出excel的若干方式总结(十四)-- 动态设置分页符

因为在导出excel表格的时候,存在一条记录占用多行,并且一次导出若干条记录。为了用户打印方便,所以要针对性对这些记录进行分页设置。以下示例,模板设计时一条记录占用7行,实测6条记录占用一页,故代码中分页以此为依据进行了分页。

模板

分页代码:
List supplyAreaList = saBiz.getSupplyAreaById(supplyAreaId);
			SupplyArea sa = (SupplyArea) supplyAreaList.get(0);
			Long id = sa.getSupplyAreaId();
			List qcList = new ArrayList();
			QueryCondition idObj = new QueryCondition();
			idObj.setFieldName("supplyAreaId");
			idObj.setQueryOperator(QueryOperator.le);
			idObj.setValue(id);
			qcList.add(idObj);
			List recordsList = saBiz.getRecords(qcList, new SupplyArea());
			String templateDir = "D:/excel/template/SupplyAreaChangeRow.xls";
			String targetDir="D:/excel/export/testChangeRow.xls";			
			BufferedInputStream bis = new BufferedInputStream(new FileInputStream(templateDir));//传入模板文件
			//InputStream bis = new BufferedInputStream(new FileInputStream(templateDir));//传入模板文件
			Map beans = new HashMap();
			beans.put("suplyArea", recordsList);
			XLSTransformer transFormer = new XLSTransformer();
			HSSFWorkbook workBook = transFormer.transformXLS(bis,beans);
			OutputStream os = new FileOutputStream(targetDir);
			HSSFSheet sheet = workBook.getSheetAt(0);
			for(int i=1;i<recordsList.size()/7+2;i++ ){
				//sheet.setAutobreaks(true);//经测试证明所有记录为一页,即不分页
				sheet.setRowBreak(i*6*7-1);//每页显示6条记录,每条记录占7行,共j页	
				sheet.setColumnBreak((short)5);
			}
			workBook.write(os);
			os.flush();
			os.close();

导出结果


打印预览


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值