600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > java“的注脚_Java 添加Word脚注 尾注

java“的注脚_Java 添加Word脚注 尾注

时间:2019-11-20 08:15:16

相关推荐

java“的注脚_Java 添加Word脚注 尾注

Word中的脚注和尾注都是对文本的补充说明。脚注一般是附在书页最左下端的注文,用以解释、说明特定内容;而尾注则是位于文档末尾,用于列出引文的出处。脚注和尾注都可以是针对某些文字或者段落来添加。本文中,将演示如何通过Java程序来添加脚注及尾注到Word文档。

注:添加脚注时,本文分给指定文本添加脚注、给指定段落添加脚注;同理,添加尾注时,也可以指定文本或段落(可参照文中对脚注的添加方法)。

使用工具:Free Spire.Doc for Java

Jar文件获取及导入:

方法1:通过官网下载jar文件包,并解压。解压文件后,将lib文件夹中的Spire.Doc.jar文件导入Java程序。

方法2:通过maven仓库导入。

Java代码示例(供参考)importcom.spire.doc.*;

importcom.spire.doc.documents.Paragraph;

importcom.spire.doc.documents.TextSelection;

importcom.spire.doc.fields.Footnote;

importcom.spire.doc.fields.TextRange;

importjava.awt.*;

publicclassAddFootnoteEndnote{

publicstaticvoidmain(String[]args){

//加载测试文档

Documentdoc=newDocument("test.doc");

//添加脚注1:给指定段落添加脚注

Paragraphpara1=doc.getSections().get(0).getParagraphs().get(2);//获取段落

Footnotefootnote1=para1.appendFootnote(FootnoteType.Footnote);//添加脚注

TextRangetext1=footnote1.getTextBody().addParagraph().appendText("详见附件内容");

text1.getCharacterFormat().setFontName("楷书");//格式化脚注标签及脚注内容

text1.getCharacterFormat().setFontSize(10);

text1.getCharacterFormat().setTextColor(newColor(255,140,0));

footnote1.getMarkerCharacterFormat().setFontName("楷书");

footnote1.getMarkerCharacterFormat().setFontSize(14);

footnote1.getMarkerCharacterFormat().setTextColor(newColor(0,0,139));

//添加脚注2:给指定文本添加脚注

TextSelection[]selections=doc.findAllString("消除缺陷",false,true);

for(TextSelectionselection:selections){

TextRangerange=selection.getAsOneRange();

Paragraphpara2=range.getOwnerParagraph();

Footnotefootnote2=para2.appendFootnote(FootnoteType.Footnote);

intindex=para2.getChildObjects().indexOf(range);

para2.getChildObjects().insert(index+1,footnote2);

TextRangetext2=footnote2.getTextBody().addParagraph().appendText("请查看操作手册");

text2.getCharacterFormat().setFontName("ArialBlack");

text2.getCharacterFormat().setFontSize(10);

text2.getCharacterFormat().setTextColor(newColor(153,50,204));

footnote2.getMarkerCharacterFormat().setFontName("Calibri");

footnote2.getMarkerCharacterFormat().setFontSize(14);

footnote2.getMarkerCharacterFormat().setTextColor(newColor(0,0,139));

//添加尾注:给指定段落添加尾注(给指定文本添加尾注可参考以上添加脚注的代码方法)

Paragraphpara3=doc.getSections().get(0).getParagraphs().get(15);

Footnoteendnote=para3.appendFootnote(FootnoteType.Endnote);

TextRangetext3=endnote.getTextBody().addParagraph().appendText("引用自刘玲《操作手册》");

text3.getCharacterFormat().setFontName("ArialBlack");

text3.getCharacterFormat().setFontSize(10);

text3.getCharacterFormat().setTextColor(newColor(135,206,204));

endnote.getMarkerCharacterFormat().setFontName("Calibri");

endnote.getMarkerCharacterFormat().setFontSize(14);

endnote.getMarkerCharacterFormat().setTextColor(newColor(0,0,139));

//保存文档

doc.saveToFile("result.docx",FileFormat.Docx_);

}

}

}

脚注添加效果:

尾注添加效果:

(本文完)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。