excel转图片(aspose.cells方式)

    /**
	 * excel转图片(aspose.cells)
	 * @param excelpath          要转成图片的excel对象
	 * @param picpath 			生成的图片路径
	 * @return 返回生成的图片对象
	 * @throws IOException
	 */
	@SuppressWarnings("deprecation")
	public static File excelToPic(String excelpath,String picpath) {
		if (!authrolizeLicense()) 
			return null;
		try {
			Workbook wb = new Workbook(excelpath);
			Worksheet sheet = wb.getWorksheets().get(0);
			ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
			imgOptions.setImageFormat(ImageFormat.getPng());
			imgOptions.setCellAutoFit(true);
			imgOptions.setOnePagePerSheet(true);
			SheetRender render = new SheetRender(sheet, imgOptions);
			render.toImage(0,picpath);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new File(picpath);
	}

    /**
	 *  转图片前的验证License,不然转成图片后会有水印
	 * 
	 * @throws IOException
	 */
	public static boolean authrolizeLicense() {
		boolean result = false;
		try {
			InputStream is =       com.aspose.cells.License.class.getResourceAsStream("/com.aspose.cells.lic_2999.xml");
			License asposeLicense = new License();
			asposeLicense.setLicense(is);
			is.close();
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值