Javaでの単語にendnoteを追加する


脚注のように、EndNoteは、メインテキストへの補足説明です.通常、引用符のソースを一覧表示するには、ドキュメントの末尾に位置します.この記事では、プログラムを自由に尖塔を使用して既存のWord文書にEndNoteを追加する方法を示します.Java用のドキュメント.

インポートの依存


方法1 : free libraryをダウンロードして解凍します.その後、尖塔を追加します.doc.Javaファイルに依存するjarファイル.
方法2 : POMに次の設定を追加することによって、MavenプロジェクトにJAR依存を直接追加します.XML
<repositories>
   <repository>
      <id>com.e-iceblue</id>
      <name>e-iceblue</name>
      <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
   </repository>
</repositories>
<dependencies>
   <dependency>
      <groupId>e-iceblue</groupId>
      <artifactId>spire.doc.free</artifactId>
      <version>5.1.0</version>
   </dependency>
</dependencies>

サンプルコード


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\\Moon.docx");

        //Get the first section
        Section section = doc.getSections().get(0);

        //Get the specific paragraph to add endnote
        Paragraph paragraph = section.getParagraphs().get(3);

        //Add an endnote
        Footnote endnote = paragraph.appendFootnote(FootnoteType.Endnote);

        //Set endnote text
        TextRange textRange = endnote.getTextBody().addParagraph().appendText("You can add the necessary endnote here.");

        //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);
    }
}