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());
                }
            }
    	}
    		
    }
    

      

  • 相关阅读:
    Android 压力测试工具Monkey
    解决maven的依赖总是无法下载完成
    JDBC连接数据库(二)
    JDBC连接数据库(一)
    webdriver js点击无法点击的元素
    多线程Java面试题总结
    PHP unset销毁变量并释放内存
    ThinkPHP函数详解:D方法
    PHP 函数:intval()
    ThinkPHP 模板显示display和assign的用法
  • 原文地址:https://www.cnblogs.com/firstdream/p/5730862.html
Copyright © 2011-2022 走看看