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

import com.spire.doc.*;importcom.spire.doc.documents.Paragraph;importcom.spire.doc.documents.TextSelection;importcom.spire.doc.fields.Footnote;importcom.spire.doc.fields.TextRange;import java.awt.*;public classAddFootnoteEndnote {public static voidmain(String[] args){//加载测试文档

Document doc = new Document("test.doc");//添加脚注1:给指定段落添加脚注

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

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

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

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

text1.getCharacterFormat().setFontSize(10);

text1.getCharacterFormat().setTextColor(new Color(255, 140, 0));

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

footnote1.getMarkerCharacterFormat().setFontSize(14);

footnote1.getMarkerCharacterFormat().setTextColor(new Color(0, 0, 139));//添加脚注2:给指定文本添加脚注

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

TextRange range=selection.getAsOneRange();

Paragraph para2=range.getOwnerParagraph();

Footnote footnote2=para2.appendFootnote(FootnoteType.Footnote);int index =para2.getChildObjects().indexOf(range);

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

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

text2.getCharacterFormat().setFontName("Arial Black");

text2.getCharacterFormat().setFontSize(10);

text2.getCharacterFormat().setTextColor(new Color(153, 50, 204));

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

footnote2.getMarkerCharacterFormat().setFontSize(14);

footnote2.getMarkerCharacterFormat().setTextColor(new Color(0, 0, 139));//添加尾注:给指定段落添加尾注(给指定文本添加尾注可参考以上添加脚注的代码方法)

Paragraph para3 = doc.getSections().get(0).getParagraphs().get(15);

Footnote endnote=para3.appendFootnote(FootnoteType.Endnote);

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

text3.getCharacterFormat().setFontName("Arial Black");

text3.getCharacterFormat().setFontSize(10);

text3.getCharacterFormat().setTextColor(new Color(135, 206, 204));

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

endnote.getMarkerCharacterFormat().setFontSize(14);

endnote.getMarkerCharacterFormat().setTextColor(new Color(0, 0, 139));//保存文档

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

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值