您的位置:首页 > 其它

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

2011-08-31 18:08 429 查看
因为在导出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();




导出结果



打印预览
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐