之前做的在线office要插入二维码图片,但是插件提供的接口只能够将图片插入在光标位置,没办法定位。恐怕openoffice,pageoffice之类的也是如此。poi也没有定位接口,猜想本质原因是不是word从整体看没有行列这个概念。但是可以换一个概念,页眉的最右边不就是右上角了。
大体思路是创建word文档对象——创建XWPFHeaderFooterPolicy对象——创建页眉对象——在页眉上创建一个段落——把段落起始点设置在最右边——对这个段落做一个新的运行——插入图片
附加核心代码,用的poi官网最新的poi3.17jar包
System.out.println(flag+"aaaaaaaaaaaaaaaaaa"+imgFilePath);
FileInputStream is = new FileInputStream(new File(flag));
FileInputStream pic = new FileInputStream(new File(imgFilePath));
XWPFDocument document = new XWPFDocument(is);
System.out.println(document);
XWPFHeaderFooterPolicy policy = document.getHeaderFooterPolicy();
System.out.println("policy");
XWPFHeader headerD = policy.createHeader(XWPFHeaderFooterPolicy.DEFAULT);
System.out.println("test3");
headerD.createParagraph();
//
XWPFParagraph paragraph = headerD.getParagraphArray(0);
paragraph.s