大家好,我想用java实现对word文档内容的读取,不知道该用什么方法,高手帮我一下吧,谢啦。

解决方案 »

  1.   

    网上找来的用java读取word文档的代码 
    public class WordTest {    public static void main(String[] args){        FileOutputStream ostream=null;
            FileInputStream  istream=null;
            try{
                istream=new FileInputStream("c:\\test.doc");            HWPFDocument doc=new HWPFDocument(istream);
                ostream =new FileOutputStream("C:\\testout.doc");
                CharacterProperties props = new CharacterProperties();            Range range=doc.getRange();
                // Slowly increase the font size
                for (int x = 8; x <= 64; x += 4){
                  // Set the half point size of the font
                  props.setFontSize(x);
                  range.insertAfter("Test write information into file",props);
                  range.insertAfter("\n\r");
                }            // Display Bold characters
                props.setBold(true);
                range.insertAfter(" Bold", props);
                range.insertAfter("\n\r");            // Display Italic characters
                props.setItalic(true);
                range.insertAfter(" Italic", props);
                range.insertAfter("\n\r");            // Display charcters with a Double Strikethrough
                props.setDoubleStrikeThrough(true);
                range.insertAfter(" Double Strikethrough", props);            // Insert an empty paragraph for readability
                range.insertAfter(new ParagraphProperties(), 0);            // Reset the character properties
                props = new CharacterProperties();
                props.setFontSize(32);            // Create a numbered list
                HWPFList list = new HWPFList(true, doc.getStyleSheet());
                int listID = doc.registerList(list);            // Insert a list entry            range.insertAfter(new ParagraphProperties(), listID, 1,0);
                props.setIco24(0xff0000);
                range.insertAfter(" Blue list entry", props);            // Insert another list entry
                range.insertAfter(new ParagraphProperties(), listID, 1, 0);
                props.setIco24(0xff);
                props.setFontSize(38);
                props.setCapitalized(true);
                range.insertAfter(" larger red capitalized", props);            //Last list entry
                range.insertAfter(new ParagraphProperties(), listID, 1,0);
                props.setIco24(0);
                props.setCapitalized(false);
                props.setCharacterSpacing(150);
                range.insertAfter(" Large character spacing", props);            doc.write(ostream);
                ostream.flush();
            }
            catch(IOException ioe){
                ioe.printStackTrace();
            }
            finally{
                 try{
                    if(ostream!=null){
                        ostream.close();
                    }
                    if(istream!=null){
                        istream.close();
                    }
                 }
                catch(IOException ioe){
                    ioe.printStackTrace();
                }
            }
        }
      

  2.   

    import java.io.*;
    import org.apache.poi.hwpf.extractor.WordExtractor;public class PdfExtractor {
      public PdfExtractor() {}  public static void main(String args[]) throws Exception {
        FileInputStream in = new FileInputStream("d:\\a.doc");
        WordExtractor extractor = new WordExtractor(in);
        String str = extractor.getText();
        System.out.println("the result is:" + str);
      }
    }
    引用了apache的开源包,你可以去官方网站下载
      

  3.   

    再问一下这个东东需要import哪些类啊,我不太懂java。
      

  4.   

    瓜瓜,哪里有apache的开源包下载呢,我找不到。大虾帮我一下吧,分不够可以加。
      

  5.   

    http://www.apache.org/dist/jakarta/poi/release/bin/
      

  6.   

    这个包的用法不仅仅是抽取WORD,里面有API,其他用法自己看
      

  7.   

    缺东西吧
    CharacterProperties 是什么