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());
		String templateDir = "D:/excel/template/SupplyAreaChangeRow.xls";
		String targetDir="D:/excel/export/testChangeRow.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);
		//将图片以字节流的方式输入输出
		String picture = "D:/excel/picture/picture1.jpg";
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		BufferedImage BufferImg = ImageIO.read(new File(picture));
		ImageIO.write(BufferImg, "JPEG", bos);
	//public HSSFClientAnchor(int dx1,int dy1,int dx2,int dy2,short col1,int row1,short col2,int row2)
	HSSFClientAnchor anchor = new HSSFClientAnchor(5,0,305,200,(short) 4, 1,(short)5,2);
		HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
patriarch.createPicture(anchor,
workBook.addPicture(bos.toByteArray(),workBook.PICTURE_TYPE_JPEG));	
		OutputStream os = new FileOutputStream(targetDir);
	     workBook.write(os);
	     is.close();
	     os.flush();
	     os.close();



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