/**
* 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;
}
excel转图片(aspose.cells方式)
于 2024-06-18 14:38:35 首次发布