menu

Document Processing

Interface IComments - FileFormats API Reference | Syncfusion

    Show / Hide Table of Contents

    Interface IComments

    A collection of cell comments. Each comment is represented by a Comment object.

    Namespace: Syncfusion.XlsIO
    Assembly: Syncfusion.XlsIO.Base.dll
    Syntax
    public interface IComments : IEnumerable

    Properties

    Application

    Used without an object qualifier, this property returns an Application object that represents the Microsoft Excel application.

    Declaration
    IApplication Application { get; }
    Property Value
    Type
    IApplication
    Examples

    The following code illustrates how to access the IApplication from the IComments collection.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2013;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Add comment
                ICommentShape comment = worksheet["C2"].AddComment();
    
                //Access application object
                Console.Write(comment.Application.DefaultVersion);
    
                //Save and dispose
                workbook.SaveAs("Comments.xlsx");
                workbook.Close();
                Console.ReadKey();
            }
    //Output will be
    //Excel2013

    Count

    Returns the number of ICommentShape objects in the IComments collection. Read-only Long.

    Declaration
    int Count { get; }
    Property Value
    Type
    System.Int32
    Examples

    The following code illustrates how to access the Count property.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        application.DefaultVersion = ExcelVersion.Excel2013;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Add comment
        worksheet["C2"].AddComment();
        worksheet["E2"].AddComment();
    
        //Get count
        Console.Write(worksheet.Comments.Count);
    
        //Save and dispose
        workbook.SaveAs("Comments.xlsx");
        workbook.Close();
        Console.ReadKey();
    }
    //Output will be
    //2

    Item[Int32]

    Returns a single ICommentShape object from the IComments collection.

    Declaration
    ICommentShape this[int Index] { get; }
    Parameters
    Type Name Description
    System.Int32 Index
    Property Value
    Type
    ICommentShape
    Examples

    The following code illustrates how to access a ICommentShape from the IComments collection.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2013;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Add comment
                worksheet["C2"].AddComment();
    
                //Set text
                worksheet.Comments[0].Text = "Comment";
    
                //Save and dispose
                workbook.SaveAs("Comments.xlsx");
                workbook.Close();
            }

    Item[Int32, Int32]

    Returns single ICommentShape object from the IComments collection by row and column one-based indexes. Read-only.

    Declaration
    ICommentShape this[int iRow, int iColumn] { get; }
    Parameters
    Type Name Description
    System.Int32 iRow
    System.Int32 iColumn
    Property Value
    Type
    ICommentShape
    Examples

    The following code illustrates how to access a ICommentShape from the IComments collection.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2013;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Add comment
                worksheet["C2"].AddComment();
    
                //Set text
                worksheet.Comments[2, 3].Text = "Comment";
    
                //Save and dispose
                workbook.SaveAs("Comments.xlsx");
                workbook.Close();
            }

    Item[String]

    Gets single ICommentShape from the IComments collection.

    Declaration
    ICommentShape this[string name] { get; }
    Parameters
    Type Name Description
    System.String name

    Name of the item to get.

    Property Value
    Type Description
    ICommentShape

    Single item from the collection.

    Examples

    The following code illustrates how to access a ICommentShape from the IComments collection.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2013;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Add comment
                ICommentShape comment = worksheet["C2"].AddComment();
    
                //Set name
                comment.Name = "Comment1";
    
                //Set text
                worksheet.Comments["Comment1"].Text = "Comment";
    
                //Save and dispose
                workbook.SaveAs("Comments.xlsx");
                workbook.Close();
            }

    Parent

    Returns the parent object for the specified object.

    Declaration
    object Parent { get; }
    Property Value
    Type
    System.Object
    Examples

    The following code illustrates how to access the parent of the IComments collection.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        application.DefaultVersion = ExcelVersion.Excel2013;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Add comment
        ICommentShape comment = worksheet["C2"].AddComment();
    
        //Access parent object
        Console.Write(comment.Parent.ToString());
    
        //Save and dispose
        workbook.SaveAs("Comments.xlsx");
        workbook.Close();
        Console.ReadKey();
    }
    //Output will be
    //Syncfusion.XlsIO.Implementation.Collections.ShapesCollection

    Methods

    Clear()

    Remove all ICommentShape from the IComments collection.

    Declaration
    void Clear()
    Examples

    The following code illustrates how to remove all the ICommentShape in the IComments collection.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2013;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Add comment
                worksheet["C2"].AddComment();
                worksheet["E2"].AddComment();
    
                //Add text
                worksheet.Comments[0].Text = "Comment1";
                worksheet.Comments[1].Text = "Comment2";
    
                //Clear comments
                worksheet.Comments.Clear();
    
                //Save and dispose
                workbook.SaveAs("Comments.xlsx");
                workbook.Close();
            }
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved