Poi reads the word content, and poi reads the word content
Pache POI is an open source library of the Apache Software Foundation. POI provides APIs for Java programs to read and write Microsoft Office files.
1. Read the jar packages required by word 2003 and word 2007.
Reading the 2003 documents (.doc) word file is relatively simple, just need poi-3.5-beta6-20090622.jar and poi-scratchpad-3.5-beta6-20090622.jar two jar packages, and 2007 documents (.docx) is too much trouble, the trouble I mentioned is not the problem when writing code. It is because there are more jar packages to be imported, including the following seven:
1. openxml4j-bin-beta.jar
2. poi-3.5-beta6-20090622.jar
3. poi-ooxml-3.5-beta6-20090622.jar
4. dom4j-1.6.1.jar
5. geronimo-stax-api_1.0_spec-1.0.jar
6. ooxml-schemas-1.0.jar
7. xmlbeans-2.3.0.jar
4-7 is the jar package on which the poi-ooxml-3.5-beta6-20090622.jar depends (which can be found under the ooxml-lib directory in the poi-bin-3.5-beta6-20090622.tar.gz ).
2.read. Doc's word Document
Public static String readDoc (File file ){
System. out. println (file. getAbsolutePath () + "....doc ");
String text = "";
FileInputStream in;
Try {
In = new FileInputStream (file );
WordExtractor extractor = new WordExtractor (in );
Text = extractor. getText ();
In. close ();
} Catch (Exception e ){
System. out. println ("Word parsing error! ");
}
Return text;
}
32.16.docx's word Document
Public static String readDocx (File file ){
System. out. println (file. getAbsolutePath () + "....docx ");
String str = "";
Try {
FileInputStream FCM = new FileInputStream (file );
XWPFDocument xdoc = new XWPFDocument (FCM );
XWPFWordExtractor extractor = new XWPFWordExtractor (xdoc );
Str = extractor. getText ();
System. out. println (str );
FCM. close ();
} Catch (Exception e ){
E. printStackTrace ();
}
Return str;
}