Jxls导出excel的若干方式总结(十三)-- 动态合并单元格

可以看到代码中指定合并的部分现在已经显示出了效果。

模板

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());
			int i = recordsList.size();
			String templateDir = "D:/excel/template/SupplyAreaDynaMergeCells.xls";
			String targetDir="D:/excel/export/testDynaMergeCells.xls";		
			InputStream is = new FileInputStream(templateDir);
			Map beans = new HashMap();
			beans.put("suplyArea", recordsList);
			//关联模板 
			XLSTransformer transformer = new XLSTransformer();
			HSSFWorkbook workBook = transformer.transformXLS(is, beans);
			HSSFSheet sheet = workBook.getSheetAt(0);
			sheet.addMergedRegion(new Region(2,(short)0,2+i,(short)0));
			sheet.addMergedRegion(new Region(2,(short)2,2+i,(short)2));
			OutputStream os = new FileOutputStream(targetDir);
	       	workBook.write(os);
	        	is.close();
	        	os.flush();
os.close();


导出结果


已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页