Using POI to extract text from Word documents
The Apache POI project (http://poi.apache.org/index.html) is an API used to extract information from Microsoft Office products. It is an extensive library that allows information extraction from Word documents and other office products, such as Excel and Outlook. When downloading the API for POI, you will also need to use XMLBeans (http://xmlbeans.apache.org/), which supports POI. The binaries for XMLBeans can be downloaded from http://www.java2s.com/Code/Jar/x/Downloadxmlbeans524jar.htm. Our interest is in demonstrating how to use POI to extract text from word documents.
To demonstrate this, we will use a file called TestDocument.docx
, with some text, tables, and other stuff, as shown in the following screenshot (we have taken the English home page of Wikipedia):
There are several different file formats used by different versions of Word. To simplify the selection of which text extraction class to use, we will use the ExtractorFactory
factory...