Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从ApachePOI读取word文档中的注释?_Java_Apache_Ms Word_Document - Fatal编程技术网

Java 如何从ApachePOI读取word文档中的注释?

Java 如何从ApachePOI读取word文档中的注释?,java,apache,ms-word,document,Java,Apache,Ms Word,Document,如何从microsoft word文档中读取word注释(批注) 如果可能,请提供一些示例代码 谢谢…获取对象(比如,通过在输入流中传递Word文档) 然后,您可以通过获取摘要,这将通过getSummary()获取对象(例如,通过在输入流中传递Word文档)为您提供一个对象 然后您可以通过获取摘要,这将通过getSummary()为您提供一个对象。最后,我找到了答案 下面是代码片段 File file = null; FileInputStream fis = null;

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

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

谢谢…

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

然后,您可以通过获取摘要,这将通过
getSummary()

获取对象(例如,通过在输入流中传递Word文档)为您提供一个对象


然后您可以通过获取摘要,这将通过
getSummary()

为您提供一个对象。最后,我找到了答案

下面是代码片段

    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();
    }
File文件=null;
FileInputStream fis=null;
HWPFDocument文件=null;
Range=null;
试一试{
文件=新文件(文件名);
fis=新文件输入流(文件);
文件=新的HWPF文件(fis);
commentRange=document.getCommentsRange();
int numComments=commentRange.numParagraphs();
对于(int i=0;i
我使用的是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


我感谢马克B的帮助,他实际上找到了这个解决方案……

最后,我找到了答案

下面是代码片段

    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();
    }
File文件=null;
FileInputStream fis=null;
HWPFDocument文件=null;
Range=null;
试一试{
文件=新文件(文件名);
fis=新文件输入流(文件);
文件=新的HWPF文件(fis);
commentRange=document.getCommentsRange();
int numComments=commentRange.numParagraphs();
对于(int i=0;i
我使用的是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的帮助,他实际找到了此解决方案……

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


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


我也是apache poi的新手。Hear是我的程序,它工作正常这个程序将word从文档提取到文本…我希望这个程序能在你运行这个程序之前帮助你在你的类路径中设置相应的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();
        }
    }
}

我对ApachePOI也是新手。Hear是我的程序,它工作正常这个程序将word从文档提取到文本…我希望这个程序能在你运行这个程序之前帮助你在你的类路径中设置相应的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();
        }
    }
}

我想阅读97/2003/xp和2007 word文件中的评论…我想阅读97/2003/xp和2007 word文件中的评论…很抱歉,它不起作用。。。它返回空值。。。实际上,我想要的是word注释(Annotation),我认为getSummary(),getComment()返回的是其他内容。。。不管怎样,谢谢大家…很抱歉,它不起作用了。。。它返回空值。。。实际上,我想要的是word注释(Annotation),我认为getSummary(),getComment()返回的是其他内容。。。无论如何,谢谢你的一切。。。