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

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

Jxls导出excel的若干方式总结(十三)-- 动态合并单元格_第1张图片

模板

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();


Jxls导出excel的若干方式总结(十三)-- 动态合并单元格_第2张图片

导出结果


你可能感兴趣的:(导出Excel)