您好我在java中编写了一个应用程序 它能够创建一个MS word .doc文件 并插入表格,图像和文字
但是,当我尝试在页脚中插入页码时,我遇到了错误 错误:运行应用程序时,整个ms-word文档变为空白
插入页脚的代码:
public void addPicture(ResumeData resumeData) {
try {
document = new CustomXWPFDocument(
new FileInputStream(
new File(
"C:\\workoutput\\assignment2\\Resume3\\ResumeTables.doc")));
FileOutputStream fos = new FileOutputStream(new File(
"C:\\workoutput\\assignment2\\Resume4\\ResumeTables.doc"));
String id = document.addPictureData(new FileInputStream(new File(
"C:\\workoutput\\assignment2\\Resume3\\header.jpg")),
Document.PICTURE_TYPE_JPEG);
document.createPicture(id,
document.getNextPicNameNumber(Document.PICTURE_TYPE_JPEG),
640, 94);
String text = "Page1";
XWPFHeaderFooterPolicy policy = document.getHeaderFooterPolicy();
if (policy == null) {
policy = new XWPFHeaderFooterPolicy(doc);
}
CTP ctP1 = CTP.Factory.newInstance();
CTR ctR1 = ctP1.addNewR();
CTText t = ctR1.addNewT();
t.setStringValue(text);
XWPFParagraph codePara = new XWPFParagraph(ctP1, document);
XWPFParagraph[] newparagraphs = new XWPFParagraph[1];
newparagraphs[0] = codePara;
policy.createFooter(policy.DEFAULT, newparagraphs);
}//end of try
catch(Exception e){
e.printStackTrace();
}
}
我一直在谷歌上寻求有关将页脚插入ms-word文档的帮助 但是,网上有关于将页脚插入ms-word
的资源很少请帮助