Java-POI:从doc文件提取文本时出现问题

时间:2020-08-25 15:19:02

标签: java apache-poi

我想从Word DOC文件中提取文本。

ClassLoader classloader =
    org.apache.poi.poifs.filesystem.POIFSFileSystem.class.getClassLoader();
URL res = classloader.getResource(
    "org/apache/poi/poifs/filesystem/POIFSFileSystem.class");
String path = res.getPath();
HWPFDocument doc = new HWPFDocument(new FileInputStream(fileNameorFilePath));
WordExtractor wordExtractor = new WordExtractor(doc);
return wordExtractor.getText();

我遇到此错误:

java.lang.NoSuchMethodError: org.apache.poi.POIDocument: method <init>()V not found

该行:HWPFDocument docx = new HWPFDocument(new FileInputStream(fileNameorFilePath));

我该如何解决?

[更新] pom.xml中的POI依赖项:

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.14</version>
</dependency>
        
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-scratchpad</artifactId>
    <version>3.0.1-FINAL</version>
    <exclusions>
        <exclusion>
            <artifactId>poi</artifactId>
            <groupId>org.apache.poi</groupId>
        </exclusion>
    </exclusions>
</dependency>

 <dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.14</version>
</dependency>

0 个答案:

没有答案