2

如何从 microsoft word 文档中读取 word 注释(注释)?

如果可能,请提供一些示例代码...

感谢您 ...

4

4 回答 4

3

终于,我找到了答案

这是代码片段...

    File file = null;
    FileInputStream fis = null;
    HWPFDocument document = null;
    Range commentRange = null;
    try {
        file = new File(fileName);
        fis = new FileInputStream(file);
        document = new HWPFDocument(fis);
        commentRange = document.getCommentsRange();
        int numComments = commentRange.numParagraphs();
        for (int i = 0; i < numComments; i++) {
            String comments = commentRange.getParagraph(i).text();
            comments = comments.replaceAll("\\cM?\r?\n", "").trim();
            if (!comments.equals("")) {
                System.out.println("comment :-  " + comments);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

我正在使用 Poi poi-3.5-beta7-20090719.jar、poi-scratchpad-3.5-beta7-20090717.jar。如果您希望使用基于 OpenXML 的文件格式,则需要其他档案 - poi-ooxml-3.5-beta7-20090717.jar 和 poi-dependencies-3.5-beta7-20090717.zip。

我感谢真正找到此解决方案的 Mark B 的帮助....

于 2009-07-24T13:16:17.103 回答
0

获取HWPFDocument对象(例如,通过在输入流中传递 Word 文档)。

然后您可以通过getSummaryInformation()获取摘要,这将为您提供SummaryInformation对象getSummary()

于 2009-07-13T19:58:42.617 回答
0

请参考以下链接,它可以满足您的要求...

http://bihag.wordpress.com/2009/11/04/how-to-read-comments-from-word-with-poi-jav/#comment-13

于 2010-05-17T08:52:04.783 回答
-1

我也是apache poi的新手。听说我的程序运行良好,该程序将单词形式的文档提取为文本...我希望该程序能在您运行该程序之前对您有所帮助,您可以在类路径中设置相应的 lib 文件。

/*
 * FileExtract.java
 *
 * Created on April 12, 2010, 9:46 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.rtf.RTFEditorKit;
import java.io.*;
import org.apache.poi.POIOLE2TextExtractor.*;
import org.apache.poi.POIOLE2TextExtractor;
import org.apache.poi.POITextExtractor;
import org.apache.poi.extractor.ExtractorFactory;
import org.apache.poi.hdgf.extractor.VisioTextExtractor;
import org.apache.poi.hslf.extractor.PowerPointExtractor;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.extractor.ExcelExtractor;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import javax.swing.text.Document;
/**
 *
 * @author ChandraMouil V
 */
public class RtfDocTextExtract {
    /** Creates a new instance of FileExtract */
    static String filePath;
    static String rtfFile;
    static FileInputStream fis;
    static int x=0;
    public RtfDocTextExtract() {
    }
    //This function for .DOC File
    public static void meth(String filePath) {
        try {
            if(x!=0){
                fis = new FileInputStream("D:/DummyRichTextFormat.doc");
                POIFSFileSystem fileSystem = new POIFSFileSystem(fis);
                WordExtractor oleTextExtractor = (WordExtractor) ExtractorFactory.createExtractor(fileSystem);
                String[] paragraphText = oleTextExtractor.getParagraphText();
                FileWriter fw = new FileWriter("E:/resume-template.txt");
                for (String paragraph : paragraphText) {
                    fw.write(paragraph);
                }
                fw.flush();
            } 
        }catch(Exception  e){
            e.printStackTrace();
        }
    }
}
于 2010-09-04T14:45:28.487 回答