如何修复maven损坏的xls文件?

时间:2017-09-06 00:37:47

标签: maven apache-poi report xls jett

我有一种用jett生成报告的方法:

    try {

        InputStream inPath = ProdutoManagedBean.class.getResourceAsStream("/template.xls");

        ExcelTransformer transformer = new ExcelTransformer();
        transformer.transform(inPath, beans);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InvalidFormatException e) {
        e.printStackTrace();
    }

我在transformer.transfom(...)中遇到InvalidFormatException:

22:44:37,803 ERROR [stderr] (default task-28) org.apache.poi.openxml4j.exceptions.InvalidFormatException: Your InputStream was neither an OLE2 stream, nor an OOXML stream

我调查了maven导致这个数据损坏,但我把过滤器工件放在pom.xml中,它仍然继续损坏:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${compiler-plugin.version}</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <nonFilteredFileExtensions>
                        <nonFilteredFileExtension>xls</nonFilteredFileExtension>
                    </nonFilteredFileExtensions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.5</version>
                <inherited>true</inherited>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <nonFilteredFileExtensions>
                        <nonFilteredFileExtension>xls</nonFilteredFileExtension>
                    </nonFilteredFileExtensions>
                </configuration>
            </plugin>
            <plugin>

1 个答案:

答案 0 :(得分:0)

我能够解决;我将此工件放在具有Web基础结构组件的项目的pom.xml中:

 <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.1.0</version>
                    <inherited>true</inherited>
                    <configuration>
                        <encoding>UTF-8</encoding>
                        <nonFilteredFileExtensions>
                            <nonFilteredFileExtension>xls</nonFilteredFileExtension>
                        </nonFilteredFileExtensions>
                </plugin>
            </plugins>
        </build>

这可能是由项目技术架构的特殊性引起的问题。