想在Java中将尾注添加到Word,试试这款国产控件
作者:互联网
Spire.Doc for Java 是一款专业的Java Word组件,开发人员使用它可以轻松地将Word文档创建、读取、编辑、转换和打印等功能集成到自己的Java应用程序中。
本文向您展示如何使用Spire.Doc for Java在Word文档中添加尾注。可下载最新版测试。
import com.spire.doc.*; import com.spire.doc.documents.Paragraph; import com.spire.doc.fields.Footnote; import com.spire.doc.fields.TextRange; import java.awt.*; public class AddEndnote { public static void main(String[] args) { //Create a Document object Document doc = new Document(); //Load the sample Word file doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.docx"); //Get the first section Section section = doc.getSections().get(0); //Get the specific paragraph to add endnote Paragraph paragraph = section.getParagraphs().get(2); //Add an endnote Footnote endnote = paragraph.appendFootnote(FootnoteType.Endnote); //Set endnote text TextRange textRange = endnote.getTextBody().addParagraph().appendText("This is an endnote created by Spire.Doc."); //Set text format of endnote textRange.getCharacterFormat().setFontName("Arial"); textRange.getCharacterFormat().setFontSize(13f); textRange.getCharacterFormat().setTextColor(Color.RED); //Save to file doc.saveToFile("AddEndnote.docx", FileFormat.Docx_2013); } }
标签:控件,Java,endnote,doc,spire,尾注,import,Word 来源: https://blog.csdn.net/mnrssj/article/details/115721991