0

I have been trying to read a .doc and .docx file and assign the text in the file into a String variable in java but I keep having the error

Exception in thread "main" java.lang.Error: Unresolved compilation problems: The type org.apache.poi.poifs.filesystem.POIFSFileSystem cannot be resolved. It is indirectly referenced from required .class files The type org.apache.poi.poifs.filesystem.DirectoryNode cannot be resolved. It is indirectly referenced from required .class files

I have the following code to test the program

 import java.io.*;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;

public class ReadDocFile
{
    public static void main(String[] args)
    {
        File file = null;
        WordExtractor extractor = null;
        try
        {

            file = new File("c:\\test.doc");
            FileInputStream fis = new FileInputStream(file.getAbsolutePath());
            HWPFDocument document = new HWPFDocument(fis);
            extractor = new WordExtractor(document);
            String[] fileData = extractor.getParagraphText();
            for (int i = 0; i < fileData.length; i++)
            {
                if (fileData[i] != null)
                    System.out.println(fileData[i]);
            }
        }
        catch (Exception exep)
        {
            exep.printStackTrace();
        }
    }
}

I have downloaded a .jar file from

https://mvnrepository.com/artifact/org.apache.poi/poi-scratchpad/3.9

I think the .jar file that I imported is incomplete. If so, can anyone give me a link for the complete library?

Gary
  • 13,303
  • 18
  • 49
  • 71
SoulRider
  • 145
  • 2
  • 3
  • 11

1 Answers1

2

You need to include poi-3.15.jar into your classpath.

You can find all poi jars & dependencies as single download here

If you are using maven,

   <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.15</version>
    </dependency>
Sundararaj Govindasamy
  • 8,180
  • 5
  • 44
  • 77
  • Hi Sundararaj Govindasamy, – SoulRider Oct 14 '16 at 17:21
  • I downloaded the poi-3.15 folder but there is no .jar file there so I don't really know what to do. Sorry I'm a noob with this stuff. How do I import the poi library to eclipse? – SoulRider Oct 14 '16 at 17:23
  • What happens if you click the download link from my answer? It will download a zip which contains everything.To add downloaded jar into eclipse you can refer this http://stackoverflow.com/a/11463590/1401019 You can upvote-accept this answer, if it helps – Sundararaj Govindasamy Oct 14 '16 at 17:53
  • The downloaded .zip file doesnt contain any .jar file so I don't see how I can use that. – SoulRider Oct 14 '16 at 18:11
  • I had the same issue with org.apache.poi v. 3.15 and 4.1.0. It works for me while importing last (for today) library version - 4.1.1 Rebuilding gradle project didn't work for me. Strange for me was that I tried to use the same library version mentioned in: http://cuonglv.com/2019/03/20/how-to-replace-text-in-word-file-using-apache-poi/ and I couldn't use the same class from mentioned v 3.15. Try to import 4.1.1. – EnGoPy Feb 03 '20 at 19:19