脚注,一般附在文章页面的底部,用于对文档某段或某处内容加以注释说明,常用在一些说明书、标书、论文等正式文书中。以此来让原文保持完整、流畅。本文将通过使用Java程序来演示如何在Word文档中添加和删除脚注。
使用工具:(免费版)Jar文件获取及导入:方法1:通过E-iceblue中文官网下载获取jar包。解压后将lib文件夹下的文件导入Java程序。(如下图)
方法2:通过maven仓库安装导入。具体安装详情参见E-iceblue中文官网。
【示例1】添加脚注情况1:在整个段落后面添加脚注。
*;*;*;*;publicclassAddFootnote{publicstaticvoidmain(String[]args){//加载示例文档Documentdoc=newDocument();("D:\\Desktop\\",_2010);//获取第一个section的第二段Paragraphpara=().get(0).getParagraphs().get(18);//在第一段后面添加脚注Footnotefootnote=();//添加脚注内容并设置字体格式TextRangetext=().addParagraph().appText("注:确属本公司产品质量问题,自购置之日起保修期为3个月。");().setFontName("ArialBlack");().setFontSize(10);().setTextColor(newColor(255,140,0));().setFontName("Calibri");().setFontSize(12);().setBold(true);().setTextColor(newColor(0,0,139));//保存文档("output/",_2010);}}脚注添加效果:
情况2:查找指定文本,并在查找的文本后面添加脚注
*;*;*;*;publicclassAddFootnote2{publicstaticvoidmain(String[]args){//加载示例文档Documentdoc=newDocument();("D:\\Desktop\\",_2010);//查找文本AC110V/220VTextSelection[]selections=("AC110V/220V",false,true);for(TextSelectionselection:selections){TextRangerange=();Paragraphpara=();//在指定文本后添加脚注Footnotefootnote=();intindex=().indexOf(range);().insert(index+1,footnote);//添加脚注内容并设置字体格式TextRangetext=().addParagraph().appText("直流电110/220伏");().setFontName("ArialBlack");().setFontSize(10);().setTextColor(newColor(255,140,0));().setFontName("Calibri");().setFontSize(12);().setBold(true);().setTextColor(newColor(0,0,139));//保存文本("output/",_2010);}}}脚注添加效果:
【示例2】删除脚注*;;*;publicclassDeleteFootnote{publicstaticvoidmain(String[]args){//加载示例文档Documentdocument=newDocument();("D:\\Desktop\\");Sectionsection=().get(0);//遍历section中的段落并获取所有脚注for(intj=0;().getCount();j++){Paragraphpara=().get(j);intindex=-1;for(inti=0,cnt=().getCount();icnt;i++){ParagraphBasepBase=(ParagraphBase)().get(i);if(pBaseinstanceofFootnote){index=i;break;}}if(index-1)//移除脚注().removeAt(index);}("output/",);}}脚注删除效果:
(本文完)
版权声明:文章来源网络聚合,如有问题请联系删除。





