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?

C# コードを使用して Word に強調マークを適用する

Posted at

強調マークは、Word 文書内の単語を目立たせるために使用されます。通常、強調する単語の上または下に点や丸が付けられます。しかし、手動で単語を選択して強調マークを適用するのは非常に手間がかかります。幸いなことに、.NET 版 Spire.Doc を使用すると、コードで簡単に強調マークを適用することができます。この記事では、.NET 版 Spire.Doc を使用して Word 文書内のテキストに強調マークを追加する方法を紹介します。

.NET 版 Spire.Doc のインストール

まず、Spire.Doc for .NET に含まれる DLL ファイルを .NET プロジェクトの参照に追加する必要があります。DLL ファイルは以下のリンクからダウンロードするか、NuGet でインストールすることができます。

PM> Install-Package Spire.Doc

指定したテキストに強調マークを適用

サンプルコードは以下の通りです:

using System;
using Spire.Doc;
using Spire.Doc.Documents;

namespace applyemphasismark
{
    class Program
    {
        static void Main(string[] args)
        {
            //Document のインスタンスを作成
            Document document = new Document();

            //ディスクから Word 文書を読み込む
            document.LoadFromFile(@"D:\testp\test.docx");

            //強調したいテキストを検索
            TextSelection[] textSelections = document.FindAllString("Spire.Doc for .NET", false, true);

            //検出したテキストに強調マークを適用
            foreach (TextSelection selection in textSelections)
            {
                selection.GetAsOneRange().CharacterFormat.EmphasisMark = Emphasis.Dot;
            }

            //文書を別の Word ファイルとして保存
            string output = "ApllyEmphasisMark.docx";
            document.SaveToFile(output, FileFormat.Docx);
        }
    }
}

一時ライセンスの申請

生成された文書の評価メッセージを削除したり、機能制限を解除したりしたい場合は、自分用に 30 日間の試用ライセンスを申請してください。

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?