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

      

  • 相关阅读:
    20-存储过程
    21-事务
    18-触发器
    19-函数
    16-pymysql模块的使用
    17-视图
    CodeForces 1369B. AccurateLee
    CodeForces 1312D.Count the Arrays(组合数学)
    CodeForces 1362D. Johnny and Contribution
    CodeForces 1363F. Rotating Substrings
  • 原文地址:https://www.cnblogs.com/firstdream/p/5730862.html
Copyright © 2011-2022 走看看