1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C#を使用してWord文書に脚注の脚注を追加する

Last updated at Posted at 2018-09-04

脚注と文末脚注は、文書に説明を追加するためにワード文書でよく使用されます。
脚注は通常、現在のページの下部またはテキストの下にあり、ドキュメント内の何かのコメントとして使用されます。注釈は通常、文書の最後にあり、引用のソースをリストするなどです。この資料では、主にC#を使用してWord文書に脚注を追加する方法について説明します。
【C#】

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace Word_Footnote_Endnote
{
    class Program
    {
        static void Main(string[] args)
        {
            //新しい単語文書オブジェクトを作成し脚注を注釈に追加する必要がある単語文書を読み込みます
            Document document = new Document();
            document.LoadFromFile("サンプル.docx", FileFormat.Docx2010);
            //最初の段落を取得する
            Paragraph paragraph = document.Sections[0].Paragraphs[0];
            //脚注を追加
            Footnote footnote = paragraph.AppendFootnote(FootnoteType.Footnote);
            //第1段では文字列井戸を検索して脚注を追加します
            DocumentObject obj = null;
            for (int i = 0; i < paragraph.ChildObjects.Count; i++)
            {
                obj = paragraph.ChildObjects[i];
                if (obj.DocumentObjectType == DocumentObjectType.TextRange)
                {
                    TextRange textRange = obj as TextRange;
                    if (textRange.Text == "井戸")
                    {
                        //脚注を添えた文字列を太いフォーマットに設定する
                        textRange.CharacterFormat.Bold = true;
                        //脚注を差し込む
                        paragraph.ChildObjects.Insert(i + 1, footnote);
                        break;
                    }
                }
            }

            //脚注を添付してフォントフォーマットを設定する            
            TextRange text = footnote.TextBody.AddParagraph().AppendText("狐と山羊脚注");
            text.CharacterFormat.FontName = "MS Gothic";
            text.CharacterFormat.FontSize = 10;
            text.CharacterFormat.TextColor = Color.DarkGray;
            footnote.MarkerCharacterFormat.FontName = "Calibri";
            footnote.MarkerCharacterFormat.FontSize = 12;
            footnote.MarkerCharacterFormat.Bold = true;
            footnote.MarkerCharacterFormat.TextColor = Color.DarkGreen;
            //第3の段落をとる
            Paragraph paragraph2 = document.Sections[0].Paragraphs[2];
            //尾注とフォーマットを設定します
            Footnote endnote = paragraph2.AppendFootnote(FootnoteType.Endnote);
            TextRange text2 = endnote.TextBody.AddParagraph().AppendText("狐と山羊注釈");
            text2.CharacterFormat.FontName = "Arial Black";
            text2.CharacterFormat.FontSize = 10;
            text2.CharacterFormat.TextColor = Color.DarkGray;
            endnote.MarkerCharacterFormat.FontName = "Calibri";
            endnote.MarkerCharacterFormat.FontSize = 12;
            endnote.MarkerCharacterFormat.Bold = true;
            endnote.MarkerCharacterFormat.TextColor = Color.DarkGreen;
            //ファイルを保存する
            document.SaveToFile("脚注を追加する.docx", FileFormat.Docx2010);
        }
    }
}

エフェクトチャートは以下の通りです
1.jpg

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?