チュートリアル

簡単にライブラリーを使用するためのチュートリアルコレクション

チュートリアル»pptnetparagraphandtext

Displaying items by tag: pptnetparagraphandtext

PowerPoint のテキストボックスに Word 文書のような段組を設定すると、情報が整理され視覚的に見やすくなり、聴衆の理解も深まります。行の長さを短くすることで読みやすさが向上し、視覚的にプロフェッショナルで美しいレイアウトが実現できます。また、限られたスペースを有効活用し、情報を豊富に表示しつつも見やすく整理されたレイアウトを提供します。本記事では、C# プロジェクトで Spire.Presentation for .NET を使用して、PowerPoint のテキストボックスに Word 文書のような段組を追加・削除する方法を紹介します。

Spire.Presentation for .NET をインストールします

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

PM> Install-Package Spire.Presentation

C# で PowerPoint のテキストボックスに段組を追加

Spire.Presentation では、Shape.TextFrame.ColumnCount プロパティで段組数を設定し、Shape.TextFrame.ColumnSpacing プロパティで段間のスペースを調整できます。手順は以下の通りです。

  • Presentation オブジェクトを作成します。
  • Presentation.LoadFromFile() メソッドを使用して PowerPoint ドキュメントを読み込みます。
  • Presentation.Slides[0] で最初のスライドを取得します。
  • IAutoShape として最初のテキストボックスオブジェクトを取得します。
  • Shape.TextFrame.ColumnCount プロパティでテキストボックスの段組数を設定します。
  • Shape.TextFrame.ColumnSpacing プロパティで段間のスペースを設定します。
  • Presentation.SaveToFile() メソッドでドキュメントを保存します。
  • C#
using Spire.Presentation;

namespace Demo
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // Presentationオブジェクトを作成する
            Presentation presentation = new Presentation();

            // PPTXファイルを読み込む
            presentation.LoadFromFile("Sample.pptx");

            // 最初のスライドを取得する
            ISlide slide = presentation.Slides[0];

            // スライド上の最初のシェイプがIAutoShape型かどうかを確認する
            if (slide.Shapes[0] is IAutoShape)
            {
                // 最初のシェイプをIAutoShapeオブジェクトにキャストする
                IAutoShape shape = (IAutoShape)slide.Shapes[0];

                // シェイプのテキストフレームの列数を2に設定する
                shape.TextFrame.ColumnCount = 2;

                // シェイプのテキストフレームの列間隔を25ポイントに設定する
                shape.TextFrame.ColumnSpacing = 10f;
            }

            // 修正されたプレゼンテーションを新しいPPTXファイルとして保存する
            presentation.SaveToFile("output/テキストボックスに段組を追加.pptx", FileFormat.Auto);

            // Presentationオブジェクトが使用したリソースを解放する
            presentation.Dispose();
        }
    }
}

C# で PowerPoint のテキストボックスに段組を追加

C# で PowerPoint のテキストボックスから段組を削除

PowerPoint のテキストボックスから段組を削除するには、Shape.TextFrame.ColumnCount プロパティを1に設定します。手順は以下の通りです。

  • Presentation オブジェクトを作成します。
  • Presentation.LoadFromFile() メソッドを使用して PowerPoint ドキュメントを読み込みます。
  • Presentation.Slides[index] プロパティでスライドを取得します。
  • IAutoShape としてテキストボックスオブジェクトを取得します。
  • Shape.TextFrame.ColumnCount = 1 と設定し、段組を削除します。
  • Presentation.SaveToFile() メソッドでドキュメントを保存します。
  • C#
using Spire.Presentation;

namespace Demo
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // Presentationオブジェクトを作成する
            Presentation presentation = new Presentation();

            // PPTXファイルを読み込む
            presentation.LoadFromFile("output/テキストボックスに段組を追加.pptx");

            // 最初のスライドを取得する
            ISlide slide = presentation.Slides[0];

            // スライド上の最初のシェイプがIAutoShape型かどうかを確認する
            if (slide.Shapes[0] is IAutoShape)
            {
                // 最初のシェイプをIAutoShapeオブジェクトにキャストする
                IAutoShape shape = (IAutoShape)slide.Shapes[0];

                // シェイプのテキストフレームの列数を1に設定する
                shape.TextFrame.ColumnCount = 1;
            }

            // 修正されたプレゼンテーションを新しいPPTXファイルとして保存する
            presentation.SaveToFile("output/テキストボックスから段組を削除.pptx", FileFormat.Auto);

            // Presentationオブジェクトが使用したリソースを解放する
            presentation.Dispose();
        }
    }
}

C# で PowerPoint のテキストボックスから段組を削除

一時ライセンスを申請する

結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。

Published in 段落とテキスト
Tagged under

リストは PowerPoint プレゼンテーションでの強力なツールであり、情報を明確かつ簡潔な形式で整理・提示することができます。重要なポイントを紹介したり、アイデアをまとめたり、重要な詳細を強調する場合でも、リストを活用することでスライドの視覚的魅力、読みやすさ、専門性を向上させることができます。この記事では、Spire.Presentation for .NET を使用して PowerPoint で番号付きリストまたは箇条書きリストを作成する方法について説明します。

Spire.Presentation for .NET をインストールします

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

PM> Install-Package Spire.Presentation

PowerPoint で番号付きリストを作成する

PowerPoint の番号付きリストは、各アイテムの前に番号または一連の数字が付けられるアイテムのリストです。通常は1から始まり、順次進行します。番号付きリストは、ステップ、指示、ランキング、特定の順序を必要とする情報などを提示するためによく使用されます。

Spire.Presentation for .NET を使用して PowerPoint プレゼンテーションに番号付きリストを作成するには、次の手順を実行します。

  • Presentation オブジェクトを作成します。
  • Presentation.Slides[0] プロパティを使用して最初のスライドを取得します。
  • ISlide.Shapes.AppendShape() メソッドを使用してスライドに図形を追加し、図形のスタイルを設定します。
  • 文字列配列内のリストの項目を指定します。
  • リストの項目に基づいて段落を作成し、ParagraphProperties.BulletType プロパティを使用して、これらの段落の箇条書きの種類を「Numbered」に設定します。
  • ParagraphProperties.BulletStyle プロパティを使用して、これらの段落の番号付き箇条書きスタイルを設定します。
  • IAutoShape.TextFrame.Paragraphs.Append() メソッドを使用して、これらの段落を図形に追加します。
  • Presentation.SaveToFile() メソッドを使用して、ドキュメントを PowerPoint ファイルに保存します。
  • C#
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace CreateNumberedList
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Presentationオブジェクトを作成する
            Presentation presentation = new Presentation();

            //最初のスライドを取得する
            ISlide slide = presentation.Slides[0];

            //スライドに図形を追加し、図形のスタイルを設定する
            IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 300, 200));
            shape.Fill.FillType = FillFormatType.None;
            shape.Line.FillType = FillFormatType.None;

            //デフォルト段落にテキストを追加する
            TextParagraph paragraph = shape.TextFrame.Paragraphs[0];
            paragraph.Text = "スキル:";
            paragraph.Alignment = TextAlignmentType.Left;
            paragraph.TextRanges[0].Fill.FillType = FillFormatType.Solid;
            paragraph.TextRanges[0].Fill.SolidColor.Color = Color.Black;

            //リスト内容を指定する
            string[] listItems = new string[] {
                " Command-line Unix",
                " Vim",
                " HTML",
                " CSS",
                " Python",
                " JavaScript",
                " SQL"
            };

            //番号付きリストを作成する
            foreach (string item in listItems)
            {
                TextParagraph textParagraph = new TextParagraph();
                textParagraph.Text = item;
                textParagraph.Alignment = TextAlignmentType.Left;
                textParagraph.TextRanges[0].Fill.FillType = FillFormatType.Solid;
                textParagraph.TextRanges[0].Fill.SolidColor.Color = Color.Black;
                textParagraph.BulletType = TextBulletType.Numbered;
                textParagraph.BulletStyle = NumberedBulletStyle.BulletArabicPeriod;
                shape.TextFrame.Paragraphs.Append(textParagraph);
            }

            //ドキュメントをPowerPointに保存する
            presentation.SaveToFile("NumberedList.pptx", FileFormat.Pptx2013);
        }
    }
}

C#:PowerPoint で番号付きリストまたは箇条書きリストを作成する

PowerPoint で記号の箇条書きリストを作成する

PowerPoint の記号の箇条書きリストでは、各アイテムを視覚的に表現するために数字の代わりに記号を使用します。このリストは、順序のない情報や特定の順序を持たないポイントの集まりを提示するのに便利です。 Spire.Presentation for .NET を使用して PowerPoint プレゼンテーションで記号の箇条書きリストを作成するには、以下の手順に従うことができます。

  • Presentation オブジェクトを作成します。
  • Presentation.Slides[0] プロパティを使用して最初のスライドを取得します。
  • ISlide.Shapes.AppendShape() メソッドを使用してスライドに図形を追加し、図形のスタイルを設定します。
  • 文字列配列内のリストの項目を指定します。
  • リスト項目に基づいて段落を作成し、ParagraphProperties.BulletType プロパティを使用して、これらの段落の箇条書きの種類を 「Symbol」 に設定します。
  • IAutoShape.TextFrame.Paragraphs.Append() メソッドを使用して、これらの段落を図形に追加します。
  • Presentation.SaveToFile() メソッドを使用して、ドキュメントを PowerPoint ファイルに保存します。
  • C#
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace CreateSymbolBulletedList
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Presentationオブジェクトを作成する
            Presentation presentation = new Presentation();

            //最初のスライドを取得する
            ISlide slide = presentation.Slides[0];

            //スライドに図形を追加し、図形のスタイルを設定する
            IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 350, 200));
            shape.Fill.FillType = FillFormatType.None;
            shape.Line.FillType = FillFormatType.None;

            //デフォルト段落にテキストを追加する
            TextParagraph paragraph = shape.TextFrame.Paragraphs[0];
            paragraph.Text = "スキル:";
            paragraph.Alignment = TextAlignmentType.Left;
            paragraph.TextRanges[0].Fill.FillType = FillFormatType.Solid;
            paragraph.TextRanges[0].Fill.SolidColor.Color = Color.Black;

            //リスト内容を指定する
            string[] listItems = new string[] {
                " Command-line Unix",
                " Vim",
                " HTML",
                " CSS",
                " Python",
                " JavaScript",
                " SQL"
            };

            //記号の箇条書きリストを作成する
            foreach (string item in listItems)
            {
                TextParagraph textParagraph = new TextParagraph();
                textParagraph.Text = item;
                textParagraph.Alignment = TextAlignmentType.Left;
                textParagraph.TextRanges[0].Fill.FillType = FillFormatType.Solid;
                textParagraph.TextRanges[0].Fill.SolidColor.Color = Color.Black;
                textParagraph.BulletType = TextBulletType.Symbol;
                shape.TextFrame.Paragraphs.Append(textParagraph);
            }

            //ドキュメントをPowerPointに保存する
            presentation.SaveToFile("SymbolBulletedList.pptx", FileFormat.Pptx2013);
        }
    }
}

C#:PowerPoint で番号付きリストまたは箇条書きリストを作成する

PowerPoint で画像の箇条書きリストを作成する

PowerPoint の画像箇条書きリストは、従来の箇条書きを小さな画像またはアイコンに置き換えます。 数字や記号を使用する代わりに、各項目は画像で表され、リストに視覚的な要素が追加されます。このリストは、豊富なビジュアルが必要な場合や、項目を表すために関連するアイコンを使用する必要がある場合によく使用されます。Spire.Presentation for .NET を使用して、PowerPoint プレゼンテーションで画像付き箇条書きリストを作成するには、以下の手順に従うことができます。

  • Presentation オブジェクトを作成します。
  • Presentation.Slides[0] プロパティを使用して最初のスライドを取得します。
  • ISlide.Shapes.AppendShape() メソッドを使用してスライドに図形を追加し、図形のスタイルを設定します。
  • 文字列配列内のリストの項目を指定します。
  • リスト項目に基づいて段落を作成し、ParagraphProperties.BulletType プロパティを使用して、これらの段落の箇条書きの種類を「Picture」に設定します。
  • ParagraphProperties.BulletPicture.EmbedImage プロパティを使用して、箇条書きとして使用する画像を設定します。
  • IAutoShape.TextFrame.Paragraphs.Append() メソッドを使用して、これらの段落を図形に追加します。
  • Presentation.SaveToFile() メソッドを使用して、ドキュメントを PowerPoint ファイルに保存します。
  • C#
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace CreateImageBulletedList
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Presentationオブジェクトを作成する
            Presentation presentation = new Presentation();

            //最初のスライドを取得する
            ISlide slide = presentation.Slides[0];

            //スライドに図形を追加し、図形のスタイルを設定する
            IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 400, 180));
            shape.Fill.FillType = FillFormatType.None;
            shape.Line.FillType = FillFormatType.None;

            //デフォルト段落にテキストを追加する
            TextParagraph paragraph = shape.TextFrame.Paragraphs[0];
            paragraph.Text = "To-Do List:";
            paragraph.Alignment = TextAlignmentType.Left;
            paragraph.TextRanges[0].Fill.FillType = FillFormatType.Solid;
            paragraph.TextRanges[0].Fill.SolidColor.Color = Color.Black;

            //リスト内容を指定する
            string[] listItems = new string[] {
                " プロジェクトとタスクの定義",
                " タスクに人を割り当てる",
                " タスクの優先度の定義",
                " タスクの進捗状況の追跡",
                " 仕事のまとめ"
            };

            //画像の箇条書きリストを作成する
            foreach (string item in listItems)
            {
                TextParagraph textParagraph = new TextParagraph();
                textParagraph.Text = item;
                textParagraph.Alignment = TextAlignmentType.Left;
                textParagraph.TextRanges[0].Fill.FillType = FillFormatType.Solid;
                textParagraph.TextRanges[0].Fill.SolidColor.Color = Color.Black;
                textParagraph.BulletType = TextBulletType.Picture;
                IImageData image = presentation.Images.Append(Image.FromFile("image.png"));
                textParagraph.BulletPicture.EmbedImage = image;
                shape.TextFrame.Paragraphs.Append(textParagraph);
            }

            //ドキュメントをPowerPointに保存する
            presentation.SaveToFile("ImageBulletedList.pptx", FileFormat.Pptx2013);
        }
    }
}

C#:PowerPoint で番号付きリストまたは箇条書きリストを作成する

一時ライセンスを申請する

結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。

Published in 段落とテキスト
Tagged under

Microsoft PowerPoint の置換機能を使用すると、特定のテキストを検索し、一度に新しいテキストに変更することができます。これは、大きな PowerPoint ドキュメント内の複数の場所で同じエラーを修正する必要がある場合に非常に便利です。この記事では、Spire.Presentation for .NET を使用して PowerPoint でテキストを置換する方法を示します。

Spire.Presentation for .NET をインストールします

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

PM> Install-Package Spire.Presentation

PowerPoint で特定のテキストの最初の出現箇所を置換する

PowerPoint 内の特定のテキストの最初の出現箇所を置換するには、すべてのスライドをループし、ISlide.ReplaceFirstText() メソッドを呼び出します。詳細な手順は次のとおりです。

  • Presentation クラスのインスタンスを初期化します。
  • Presentation.LoadFromFile() メソッドを使用して PowerPoint ドキュメントを読み込みます。
  • PowerPoint ドキュメント内のすべてのスライドをループします。
  • ISlide.ReplaceFirstText() メソッドを使用して、最初に出現する「Spire.Presentation for .NET」を「E-iceblue 製品」に置き換えます。
  • Presentation.SaveToFile() メソッドを使用して結果文書を保存します。
  • C#
  • VB.NET
using Spire.Presentation;

namespace ReplaceFirstTextOccurrenceInPPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //Presentationインスタンスを作成する
            Presentation ppt = new Presentation();

            //PowerPointドキュメントをロードする
            ppt.LoadFromFile("Sample1.pptx");

            //すべてのスライドをループする
            foreach (ISlide slide in ppt.Slides)
            {
                //最初に出現する「Spire.Presentation for .NET」を「E-iceblue製品」に置き換える
                slide.ReplaceFirstText("Spire.Presentation for .NET", "E-iceblue製品", false);
                break;
            }

            //結果文書を保存する
            ppt.SaveToFile("ReplaceFirstTextOccurrence.pptx", FileFormat.Pptx2013);
        }
    }
}
Imports Spire.Presentation

Namespace ReplaceFirstTextOccurrenceInPPT
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())

            'Presentationインスタンスを作成する
            Dim ppt As Presentation = New Presentation()

            'PowerPointドキュメントをロードする
            ppt.LoadFromFile("Sample1.pptx")

            'すべてのスライドをループする
            For Each slide As ISlide In ppt.Slides

                '最初に出現する「Spire.Presentation for .NET」を「E-iceblue製品」に置き換える
                slide.ReplaceFirstText("Spire.Presentation for .NET", "E-iceblue製品", False)
                Exit For
            Next

            '結果文書を保存する
            ppt.SaveToFile("ReplaceFirstTextOccurrence.pptx", FileFormat.Pptx2013)

        End Sub
    End Class
End Namespace

C#/VB.NET:PowerPoint 内のテキストを置換する方法

PowerPoint で特定のテキストのすべての出現箇所を置換する

PowerPoint 内の特定のテキストのすべての出現箇所を置換するには、すべてのスライドをループし、ISlide.ReplaceAllText() メソッドを使用します。詳細な手順は次のとおりです。

  • Presentation クラスのインスタンスを初期化します。
  • Presentation.LoadFromFile() メソッドを使用して PowerPoint ドキュメントを読み込みます。
  • PowerPoint 内のすべてのスライドをループします。
  • ISlide.ReplaceAllText() メソッドを使用して、すべての「Spire.Presentation for.NET」を「E-icelue 製品」に置き換えます。
  • Presentation.SaveToFile() メソッドを使用して結果文書を保存します。
  • C#
  • VB.NET
using Spire.Presentation;

namespace ReplaceAllTextOccurrencesInPPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //Presentationインスタンスを作成する
            Presentation ppt = new Presentation();

            //PowerPointドキュメントをロードする
            ppt.LoadFromFile("Sample1.pptx");

            //すべてのスライドをループする
            foreach (ISlide slide in ppt.Slides)
            {
                //すべての「Spire.Presentation for.NET」を「E-icelue製品」に置き換える
                slide.ReplaceAllText("Spire.Presentation for .NET", "E-iceblue製品", false);
            }
            //結果文書を保存する
            ppt.SaveToFile("ReplaceAllTextOccurrences.pptx", FileFormat.Pptx2013);

        }
    }
}
Imports Spire.Presentation

Namespace ReplaceAllTextOccurrencesInPPT
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())

            'Presentationインスタンスを作成する
            Dim ppt As Presentation = New Presentation()

            'PowerPointドキュメントをロードする
            ppt.LoadFromFile("Sample1.pptx")

            'すべてのスライドをループする
            For Each slide As ISlide In ppt.Slides

                'すべての「Spire.Presentation for.NET」を「E-icelue製品」に置き換える
                slide.ReplaceAllText("Spire.Presentation for .NET", "E-iceblue製品", False)
            Next

            '結果文書を保存する
            ppt.SaveToFile("ReplaceAllTextOccurrences.pptx", FileFormat.Pptx2013)

        End Sub
    End Class
End Namespace

C#/VB.NET:PowerPoint 内のテキストを置換する方法

PowerPoint で正規表現を使用してテキストを置換する

Spire.Presentation for .NET では、正規表現パターンに一致するテキストを置換するための IShape.ReplaceTextWithRegex() メソッドが提供されています。詳細な手順は次のとおりです。

  • Presentation クラスのインスタンスを初期化します。
  • Presentation.LoadFromFile() メソッドを使用して PowerPoint ドキュメントを読み込みます。
  • PowerPoint 内のすべてのスライドをループします。
  • 各スライドのすべての図形をループします。
  • IShape.ReplaceTextWithRegex() メソッドを使用して、正規表現パターンに一致するテキストを置き換えます。
  • Presentation.SaveToFile() メソッドを使用して結果文書を保存します。
  • C#
  • VB.NET
using Spire.Presentation;
using System.Text.RegularExpressions;

namespace ReplaceTextUsingRegexInPPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //Presentationインスタンスを作成する
            Presentation ppt = new Presentation();

            //PowerPointドキュメントをロードする
            ppt.LoadFromFile("Sample2.pptx");

            //すべてのスライドをループする
            foreach (ISlide slide in ppt.Slides)
            {
                //各スライドのすべての図形をループする
                foreach (IShape shape in slide.Shapes)
                {
                    //スライド上の # で始まるテキストを「Spire.Presentation for .NET」に置き換えます。
                    shape.ReplaceTextWithRegex(new Regex(@"\#\w+\b"), " Spire.Presentation for .NET ");
                }
            }
            //結果文書を保存する
            ppt.SaveToFile("ReplaceTextUsingRegex.pptx", FileFormat.Pptx2013);
        }
    }
}
Imports Spire.Presentation
Imports System.Text.RegularExpressions

Namespace ReplaceTextUsingRegexInPPT
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())

            'Presentationインスタンスを作成する
            Dim ppt As Presentation = New Presentation()

            'PowerPointドキュメントをロードする
            ppt.LoadFromFile("Sample2.pptx")

            'すべてのスライドをループする
            For Each slide As ISlide In ppt.Slides

                '各スライドのすべての図形をループする
                For Each shape As IShape In slide.Shapes

                    'スライド上の # で始まるテキストを「Spire.Presentation for .NET」に置き換える
                    shape.ReplaceTextWithRegex(New Regex("\#\w+\b"), " Spire.Presentation for .NET ")
                Next
            Next

            '結果文書を保存する
            ppt.SaveToFile("ReplaceTextUsingRegex.pptx", FileFormat.Pptx2013)
        End Sub
    End Class
End Namespace

C#/VB.NET:PowerPoint 内のテキストを置換する方法

一時ライセンスを申請する

結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。

Published in 段落とテキスト
Tagged under

PowerPoint プレゼンテーションを作成または編集する際、時折、特定の重要な内容を強調して観客の注意を引きたいと思うことがあります。そのためには、特定のテキストを目立つ色で強調表示するという方法が効果的です。この記事では、Spire.Presentation for .NET を使用して PowerPoint プレゼンテーションでテキストをハイライトする方法を示します。

Spire.Presentation for .NET をインストールします

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

PM> Install-Package Spire.Presentation

PowerPoint でテキストをハイライトする

Spire.Presentation for .NET が提供する IAutoShape.TextFrame.HighLightText() メソッドは、PowerPoint で指定されたテキストのハイライトをサポートします。以下に詳細な操作手順を示します。

  • Presentation クラスのインスタンスを初期化します。
  • Presentation.LoadFromFile() メソッドを使用して、PowerPoint プレゼンテーションを読み込みます。
  • プレゼンテーション内のスライドと形状をループします。
  • 現在の形状が IAutoShape 型であるかどうかを確認します。
  • 結果が true の場合は、形状を IAutoShape にキャストします。
  • TextHighLightingOptions クラスのインスタンスを初期化します。
  • TextHighLightingOptions.WholeWordsOnlyTextHighLightingOptions.CaseSensitive のプロパティを使用して、単語全体のみや大文字小文字の区別など、テキストのハイライトオプションを設定します。
  • IAutoShape.TextFrame.HighLightText() メソッドを使用して、形状内の特定のテキストをハイライトします。
  • Presentation.SaveToFile() メソッドを使用して結果ファイルを保存します。
  • C#
  • VB.NET
using Spire.Presentation;
using System.Drawing;

namespace HighlightTextInPPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //Presentationクラスのインスタンスを作成する
            Presentation presentation = new Presentation();

            //PowerPointプレゼンテーションをロードする	
            presentation.LoadFromFile(@"Sample.pptx");

            //すべてのスライドをループする
            for (int i = 0; i < presentation.Slides.Count; i++)
            {
                //現在のスライドを取得する
                ISlide slide = presentation.Slides[i];

                //スライドの形状をループする
                for (int j = 0; j < slide.Shapes.Count; j++)
                {
                    //現在の形状が IAutoShape タイプであるかどうかを確認する
                    if (slide.Shapes[j] is IAutoShape)
                    {
                        //形状をIAutoShapeに型キャストする
                        IAutoShape shape = slide.Shapes[j] as IAutoShape;

                        //TextHighLightingOptionsクラスのインスタンスを作成する
                        TextHighLightingOptions options = new TextHighLightingOptions();

                        //テキストのハイライトオプションを設定する
                        options.CaseSensitive = true;
                        options.WholeWordsOnly = true;

                        //形状内の特定のテキストをハイライトする
                        shape.TextFrame.HighLightText("Spire.Presentation for .NET", Color.LightYellow, options);
                    }
                }
            }
            //結果ファイルを保存する
            presentation.SaveToFile("HighlightText.pptx", FileFormat.Pptx2013);
        }
    }
}
Imports Spire.Presentation
Imports System.Drawing

Namespace HighlightTextInPPT
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())

            'Presentationクラスのインスタンスを作成する
            Dim presentation As Presentation = New Presentation()

            'PowerPointプレゼンテーションをロードする
            presentation.LoadFromFile("Sample.pptx")

            'すべてのスライドをループする
            For i As Integer = 0 To presentation.Slides.Count – 1

                '現在のスライドを取得する
                Dim slide As ISlide = presentation.Slides(i)

                'スライドの形状をループする
                For j As Integer = 0 To slide.Shapes.Count – 1

                    '現在の形状が IAutoShape タイプであるかどうかを確認する
                    If TypeOf slide.Shapes(j) Is IAutoShape Then

                        '形状をIAutoShapeに型キャストする
                        Dim shape As IAutoShape = TryCast(slide.Shapes(j), IAutoShape)

                        'TextHighLightingOptionsクラスのインスタンスを作成する
                        Dim options As TextHighLightingOptions = New TextHighLightingOptions()

                        'テキストのハイライトオプションを設定する
                        options.CaseSensitive = True
                        options.WholeWordsOnly = True

                        '形状内の特定のテキストをハイライトする
                        shape.TextFrame.HighLightText("Spire.Presentation for .NET", Color.LightYellow, options)
                    End If
                Next
            Next

            '結果ファイルを保存する
            presentation.SaveToFile("HighlightText.pptx", FileFormat.Pptx2013)
        End Sub
    End Class
End Namespace

C#/VB.NET:PowerPoint 内のテキストをハイライトする方法

一時ライセンスを申請する

結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。

Published in 段落とテキスト
Tagged under

PowerPoint 文書内に多くのメディアファイルや画像が含まれており、他者にテキスト校正のために送信する場合、大きなファイルサイズのため転送速度が遅いことがあります。そのような場合は、まず PowerPoint からテキストを Word 文書またはメモ帳に抽出し、テキスト内容のみを送信することが良いです。また、抽出されたテキスト内容は、将来の参照のためにアーカイブまたはバックアップすることもできます。この記事では、Spire.Presentation for .NET を使用して、C# および VB.NET で PowerPoint プレゼンテーションからテキストを抽出する方法を示します。

Spire.Presentation for.NET をインストールします

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

PM> Install-Package Spire.Presentation

C# と VB.NET で PowerPoint プレゼンテーションからテキストを抽出する

PowerPoint プレゼンテーション内のテキスト情報を共有または配信する必要がある場合があります。その際には、テキスト抽出操作が必要です。以下は、すべてのスライドからテキストを抽出して TXT ファイルに保存する手順です。

  • Presentation クラスのインスタンスを初期化します。
  • Presentation.LoadFromFile() メソッドを使用してサンプル PowerPoint 文書を読み込みます。
  • StringBuilder インスタンスを作成します。
  • 文書内の各スライドをループし、各スライド内のすべての図形をループします。
  • 図形が IAutoShape タイプであるかどうかを判断します。はいの場合は、各図形のすべての段落をループし、TextParagraph.Text プロパティを使用して段落テキストを取得します。
  • StringBuilder.AppendLine() メソッドを使用して、抽出したテキストを StringBuilder インスタンスに追加します。
  • 新しい txt ファイルを作成し、File.WriteAllText() メソッドを使用して抽出したテキストをこのファイルに書き込みます。
  • C#
  • VB.NET
using Spire.Presentation;
using System.IO;
using System.Text;
namespace ExtractText
{
    class Program
    {
        static void Main(string[] args)
        {
            //Presentationクラスのインスタンスを初期化する
            Presentation presentation = new Presentation();

            //サンプル PowerPoint 文書を読み込む
            presentation.LoadFromFile("sample.pptx");
            //StringBuilderインスタンスを作成する
            StringBuilder sb = new StringBuilder();

            //文書内の各スライドをループする
            foreach (ISlide slide in presentation.Slides)
            {
                //各スライド内のすべての図形をループする
                foreach (IShape shape in slide.Shapes)
                {
                    //図形が IAutoShape タイプであるかどうかを判断する
                    if (shape is IAutoShape)
                    {
                        //各図形のすべての段落をループする
                        foreach (TextParagraph tp in (shape as IAutoShape).TextFrame.Paragraphs)
                        {
                            //抽出したテキストを StringBuilder インスタンスに追加する
                            sb.AppendLine(tp.Text);
                        }
                    }
                }
            }
            //抽出されたテキストを保存するための新しいtxtファイルを作成する
            File.WriteAllText("ExtractText.txt", sb.ToString());
           
            //ドキュメントを閉じる
            presentation.Dispose();
        }
    }
}
Imports Spire.Presentation
Imports System.IO
Imports System.Text

Namespace ExtractText
    Class Program
        Private Shared Sub Main(ByVal args() As String)

            'Presentationクラスのインスタンスを初期化する
            Dim presentation As Presentation = New Presentation

            'サンプル PowerPoint 文書を読み込む
            presentation.LoadFromFile("sample.pptx")

            'StringBuilderインスタンスを作成する
            Dim sb As StringBuilder = New StringBuilder

            '文書内の各スライドをループする
            For Each slide As ISlide In presentation.Slides

                '各スライド内のすべての図形をループする
                For Each shape As IShape In slide.Shapes

                    '図形が IAutoShape タイプであるかどうかを判断する
                    If (TypeOf shape Is IAutoShape) Then

                        '各図形のすべての段落をループする
                        For Each tp As TextParagraph In CType(shape, IAutoShape).TextFrame.Paragraphs

                            '抽出したテキストを StringBuilder インスタンスに追加する
                            sb.AppendLine(tp.Text)
                        Next
                    End If
                Next
            Next

            '抽出されたテキストを保存するための新しいtxtファイルを作成する
            File.WriteAllText("ExtractText.txt", sb.ToString)
            
            'ドキュメントを閉じる
            presentation.Dispose()
        End Sub
    End Class
End Namespace

C#/VB.NET:PowerPoint プレゼンテーションからテキストを抽出する方法

一時ライセンスを申請する

結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。

Published in 段落とテキスト
Tagged under