zoukankan      html  css  js  c++  java
  • poi获取word批注

    package test;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;
    
    import org.apache.poi.xwpf.model.XWPFCommentsDecorator;
    import org.apache.poi.xwpf.usermodel.XWPFDocument;
    import org.apache.poi.xwpf.usermodel.XWPFParagraph;
    /**
     * 获取word批注 poi3.14
     * @author Administrator
     *
     */
    public class GetPiZhuFromWord {
    	private static XWPFDocument comments;
    	public static File getFile(String sampleFileName) {
            File f = new File(sampleFileName);
            return f;
        }
    	public static InputStream openResourceAsStream(String sampleFileName) {
            File f = getFile(sampleFileName);
            try {
                return new FileInputStream(f);
            } catch (FileNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    	
    	public static XWPFDocument openSampleDocument(String sampleName) throws IOException {
            InputStream is = openResourceAsStream(sampleName);
            return new XWPFDocument(is);
        }
    	public static void set() throws IOException {
            comments = openSampleDocument("C:\WordWithAttachments.docx");
        }
    	public static void main(String[] args) throws IOException{
    		set();
    		testComments();
    	}
    	 public static void testComments() {
    		int numComments = 0;
            for (XWPFParagraph p : comments.getParagraphs()) {
                XWPFCommentsDecorator d = new XWPFCommentsDecorator(p, null);
                if (d.getCommentText().length() > 0) {
                    numComments++;
                    System.out.println(d.getCommentText());
                }
            }
    	}
    		
    }
    

      

  • 相关阅读:
    GridView绑定模板格式化日期总结
    统计静态页点击量
    行业网seo诊断
    查看sql执行效率
    ItemCommandVSItemDataBound
    【转帖】我眼中的flash和silverlight
    修改SQLserver数据库中的a表的一列等于b表的一列
    过河卒
    最长公共子序列LCS
    情感日记:在中国地质大学的日子
  • 原文地址:https://www.cnblogs.com/firstdream/p/5730862.html
Copyright © 2011-2022 走看看