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

      

  • 相关阅读:
    php字符串
    碰撞检测
    javascript倒计时
    日期
    雪花那个飘
    VBS学习笔记(2): Call造成的麻烦
    VBS学习笔记(3): Array和Collection的不同
    NotepadAutomationDemo的代码V2
    VBS学习笔记(1): Set的取舍
    SQL Server之旅:(三)Attach mdf without ldf
  • 原文地址:https://www.cnblogs.com/firstdream/p/5730862.html
Copyright © 2020-2023  润新知