如何将图像作为页眉添加到 XWPF 文档中的每一页?我已经尝试了我能想到的所有可能的事情,下面是我的代码:
XWPFDocument docx = new XWPFDocument();
CTSectPr sectPr = docx.getDocument().getBody().addNewSectPr();
XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(docx, sectPr);
XWPFHeader header = policy.createHeader(XWPFHeaderFooterPolicy.FIRST);
String imgFile="sample.png";
header.addPictureData(new FileInputStream(imgFile), XWPFDocument.PICTURE_TYPE_PNG);
String nameoffile ="customer"+".docx";
FileOutputStream out = new FileOutputStream(nameoffile);
docx.write(out);
out.close();
但是,这在 java.lang.IndexOutOfBoundsException 行给了我一个 java.lang.IndexOutOfBoundsException