无法解析xwpf

时间:2014-05-05 12:51:46

标签: java maven apache-poi xwpf

我正在尝试使用POI将word文件转换为txt文件,但是当我使用org.apache.poi.xwpf.usermodel.XWPFDocument时,它告诉我“无法解析xwpf”

我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0         http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>convert</groupId>
<artifactId>convertor</artifactId>
<version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.10-FINAL</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.6.0</version>
        </dependency>

    </dependencies>

当我运行clean & package时,它会给我success。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:4)

根据Apache POI Components page,对于XWPF,您需要将poi-ooxml maven工件作为依赖项

因此,您的pom会看起来像这样:

<properties>
    <poi.version>3.10-FINAL</poi.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>${poi.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>${poi.version}</version>
    </dependency>
</dependencies>