使用poi操作office文档出现的问题解决方案

问题场景:

将富文本内容转换成doc文档并导出,原始代码在之前的项目中没问题,在pigx项目中会报错。

错误位置:

XWPFTemplate template = XWPFTemplate.compile(emptydoc)读取office文件流报错。

报错内容:

org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException Create breakpoint: No valid entries or contents found, this is not a valid 00xML (office Open XML) file

解决方案:

所使用的pigx框架在编译过程中不会忽略resource目录下的文件编译,因此office文件会被编译后认为不是一个正常的office文件。所以在pom.xml中build打包设置中加上忽略特定格式文件的编译即可,加上后就不会在此处报错了。

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<configuration>
					<nonFilteredFileExtensions>
						<nonFilteredFileExtension>docx</nonFilteredFileExtension>
					</nonFilteredFileExtensions>
				</configuration>
			</plugin>
			<plugin>
				<groupId>io.fabric8</groupId>
				<artifactId>docker-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

猜你喜欢

转载自blog.csdn.net/xinleiweikai/article/details/129325963