1

我有一种使用 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>
4

1 回答 1

1

我能够解决;我将此工件放在具有 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>

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

于 2017-09-07T12:03:37.220 回答