チュートリアル

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

チュートリアル».NET»Spire.Presentation for .NET»コメントとノート»C#/VB.NET:PowerPoint のコメントを追加また削除する方法
2022-08-15

C#/VB.NET:PowerPoint のコメントを追加また削除する方法

Microsoft PowerPoint では、コメントとは、スライドに追加できるフレーズや段落のノートであり、非常に実用的な機能です。例えば、著者はコメントを追加することで、読者にドキュメントの内容に関する詳細な情報を理解するのを助けることができます。同様に、読者はコメントを追加することで著者に意見やフィードバックを提供することもできます。また、コメントが不要になった場合は、いつでも削除することができます。この記事では、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

PowerPoint のコメントを追加する方法

次の手順は、PowerPoint のコメントを追加する方法を示しています。

  • Presentation クラスのインスタンスを作成します。
  • Presentation.LoadFromFile() メソッドを使用して、PowerPoint ドキュメントをロードします。
  • Presentation.CommentAuthors プロパティを使用して、CommentAuthor リストを取得します。
  • CommentAuthorList.AddAuthor() メソッドを使用して、コメントの著者を追加します。
  • Presentation.Slides[] プロパティを使用して、指定スライドを取得します。ISlide.AddComment(ICommentAuthor, String, PointF, DateTime) メソッドを使用して、スライドにコメントを追加します。
  • PresentationSaveToFile() メソッドを使用して、結果ドキュメントを保存します。
  • C#
  • VB.NET
using Spire.Presentation;
using System;

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

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

            //コメントの著者を追加する 
            ICommentAuthor author = presentation.CommentAuthors.AddAuthor("E-iceblue", "コメント:");

            //指定スライドにコメントを追加
            presentation.Slides[0].AddComment(author, "Spire.Presentationの機能の概要", new System.Drawing.PointF(25, 22), DateTime.Now);

            //結果ドキュメントを保存する
            presentation.SaveToFile("comment.pptx", FileFormat.Pptx2010);
        }
    }
}
Imports Spire.Presentation
Imports System
 
Namespace AddComment
    Class Program
        Shared  Sub Main(ByVal args() As String)
            ' Pesentationクラスのインスタンスを作成する
            Dim presentation As Presentation =  New Presentation() 
 
            ' PowerPointドキュメントをロードする
            presentation.LoadFromFile("Test.pptx")
 
            'コメントの著者を追加する 
            Dim author As ICommentAuthor =  presentation.CommentAuthors.AddAuthor("E-iceblue","コメント:") 
 
            '指定スライドにコメントを追加
            presentation.Slides(0).AddComment(author,"Spire.Presentationの機能の概要",New System.Drawing.PointF(25,22),DateTime.Now)
 
            '結果ドキュメントを保存する
            presentation.SaveToFile("comment.pptx", FileFormat.Pptx2010)
        End Sub
    End Class
End Namespace

C#/VB.NET:PowerPoint のコメントを追加また削除する方法

PowerPoint のコメントを削除する方法

次の手順は、PowerPoint のコメントを削除する方法を示しています。

  • Presentation クラスのインスタンスを作成します。
  • Presentation.LoadFromFile() メソッドを使用して、PowerPoint ドキュメントをロードします。
  • Presentation.Slides[] プロパティを使用して、指定スライドを取得します。
  • ISlide.DeleteComment(Comment) メソッドを使用して、指定スライドからコメントを削除します。
  • PresentationSaveToFile() メソッドを使用して、結果ドキュメントを保存します。
  • C#
  • VB.NET
using Spire.Presentation;

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

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

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

            //指定スライドからコメントを削除する
            slide.DeleteComment(slide.Comments[0]);

            //結果ドキュメントを保存する
            presentation.SaveToFile("RemoveComment.pptx", FileFormat.Pptx2010);

        }
    }
}
Imports Spire.Presentation
 
Namespace RemoveComment
    Class Program
        Shared  Sub Main(ByVal args() As String)
            ' Pesentationクラスのインスタンスを作成する
            Dim presentation As Presentation =  New Presentation() 
 
            ' PowerPointドキュメントをロードする
            presentation.LoadFromFile("comment.pptx")
 
            '最初のスライドを取得する
            Dim slide As ISlide =  presentation.Slides(0) 
 
            '指定スライドからコメントを削除する
            slide.DeleteComment(slide.Comments(0))
 
            '結果ドキュメントを保存する
            presentation.SaveToFile("RemoveComment.pptx", FileFormat.Pptx2010) 
 
        End Sub
    End Class
End Namespace

C#/VB.NET:PowerPoint のコメントを追加また削除する方法

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

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

Read 736 times