Poi reads the word content, and poi reads the word content

Source: Internet
Author: User

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;

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.