Aspose.cells是收费的,官网提供试用版,可以百度破解版
官网地址:
https://www.aspose.com/
引入jar包:
jar包放在工程里lib文件夹下,然后在pom.xml里配置jar包相对路径,如下所示
pom.xml中配置jar所在路径
<dependency> <groupId>com.aspose</groupId> <artifactId>aspose</artifactId> <version>8.5.2</version> <scope>system</scope> <systemPath>${basedir}/lib/aspose-cells-8.5.2.jar</systemPath> </dependency>
代码:
public class Test { /** * 获取license * * @return */ public static boolean getLicense() { boolean result = false; try { InputStream is = Test.class.getClassLoader().getResourceAsStream("/UploadModePage/license.xml"); License aposeLic = new License(); aposeLic.setLicense(is); result = true; } catch (Exception e) { e.printStackTrace(); } return result; } /** * 支持DOC, DOCX, OOXML, RTF, HTML, OpenDocument, PDF, EPUB, XPS, SWF等相互转换<br> * * @param args */ public static void main(String[] args) { // 验证License if (!getLicense()) { return; } try { Workbook wb = new Workbook("D:\\AddImage.xlsx");// 原始excel路径 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, "D:\\SheetImage.png"); } catch (Exception e) { e.printStackTrace(); } } }
如果不验证License,生成的图片,最上方会有一小排水印
官网教程:
https://docs.aspose.com/cells/java/developer-guide/
转换相关的,如下图红框中的文档