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();
导出结果
打印预览
相关文章推荐
- Jxls导出excel的若干方式总结(十二)-- 在导出报表中动态插入图片
- Jxls导出excel的若干方式总结(十三)-- 动态合并单元格
- Jxls导出excel的若干方式总结(六)-- 分sheet导出查询记录,每条记录一个sheet
- Jxls导出excel的若干方式总结(七)-- 导出查询记录到一个sheet,每条记录独占一块区域
- Jxls导出excel的若干方式总结(十五)-- 简单分析与总结
- Jxls导出excel的若干方式总结(八)-- 导出一条查询记录到多个sheet
- Jxls导出excel的若干方式总结(八)-- 导出一条查询记录到多个sheet
- Jxls导出excel的若干方式总结(九)-- 通过excel模板,直观的利用输入输出流导出excel
- Jxls导出excel的若干方式总结(一)-- Jdbc方式( ResultSetCollection )
- Jxls导出excel的若干方式总结(十)-- 在导出报表中插入单张图片
- Jxls导出excel的若干方式总结(六)-- 分sheet导出查询记录,每条记录一个sheet
- Jxls导出excel的若干方式总结(十一)-- 同一个sheet中显示来自不同数据表的对象记录
- Jxls导出excel的若干方式总结(二)-- Jdbc方式(RowSetDynaClass)
- Jxls导出excel的若干方式总结(三)-- List方式+ el表达式
- Jxls导出excel的若干方式总结(四)-- jdbc方式(RowSetDynaClass)+ jx标签库
- Jxls导出excel的若干方式总结(五)-- Simple Query
- Jxls导出excel的若干方式总结(一)-- Jdbc方式( ResultSetCollection )
- 工作总结之----动态导出数据到Excel,多sheet页
- ASP.NET 之 常用类、方法的超级总结,并包含动态的EXCEL导入导出功能,奉上类库源码
- 【飞秋】ASP.NET 之 常用类、方法的超级总结,并包含动态的EXCEL导入导出功能,奉上类库源码