目录结构
- 前言
- 支持的文件格式
- 代码整理
- maven依赖
- 文本文档解析转换
- 电子表格解析转换
- 演示文档解析转换
- PDF解析转换
- 小编代码整理(完整版)
- 特别感谢
- 扩展

前言
近期公司需求,要将office文件提取第一页内容转成图片;一番调查后整理如下:
支持的文件格式
| 文本文档 | 电子表格 | 演示文档 | |
|---|---|---|---|
| doc | xls | pot | |
| docm | xlsm | potm | |
| docx | xlsx | potx | |
| dot | xlt | pps | |
| dotx | xltm | ppsm | |
| dps | xltx | ppsx | |
| dpt | eis | ppt | |
| wps | et | pptm | |
| wpt | ett | pptx | |
| rtf | dps | ||
| dpt |
代码整理
maven依赖
如与小编需求相同,此处只需引入“spire.office.free”即可,如只需解析某一类文件,可查参考"e-iceblue",按需引入自己需要的依赖及版本;谨记不要各种类型分开添加maven依赖,否则会相互冲突解析出错;
Spire.doc和Spire.doc.free是两个不同的版本,主要区别在于是否收费以及功能多少。
Spire.doc是收费版,可能包含水印,但功能齐全。
Spire.doc.free是免费版,没有水印,但功能较少。
<repositories><repository><id>com.e-iceblue</id><name>e-iceblue</name><url>https://repo.e-iceblue.cn/repository/maven-public/</url></repository>
</repositories>
<dependencies><!--<dependency><groupId>e-iceblue</groupId><artifactId>spire.office</artifactId><version>9.1.10</version></dependency>--><dependency><groupId>e-iceblue</groupId><artifactId>spire.office.free</artifactId><version>5.3.1</version></dependency>
</dependencies>

文本文档解析转换
/*** @description: 文本文档解析转换* @author: Mr.Jkx* @time: 2024/1/30 15:08*/public static void wordPageToImage(String inputFilrPath, String outFilePath) {Document doc = new Document(inputFilrPath);//将指定页保存为BufferedImageBufferedImage image = doc.saveToImages(0, ImageType.Bitmap);//将图片数据保存为PNG格式文档File file = new File(outFilePath);try {ImageIO.write(image, "PNG", file);} catch (IOException e) {e.printStackTrace();}}
电子表格解析转换
/*** @description: 电子表格解析转换* @author: Mr.Jkx* @time: 2024/1/30 15:09*/public static void xlsPageToImage(String inputFilrPath, String