Class Comment

Comment class

Encapsulates the object that represents a cell comment.

public class Comment

Properties

NameDescription
Author { get; set; }Gets and sets Name of the original comment author
AutoSize { get; set; }Indicates if size of comment is adjusted automatically according to its content. Note: In some special cases (such as Mac environment), this setting may not take effect. If this setting does not take effect, please replace it with FitToTextSize().
Column { get; }Gets the column index of the comment.
CommentShape { get; }Get a Shape object that represents the shape attached to the specified comment.
Font { get; }Gets the font of comment.
Height { get; set; }Represents the Height of the comment, in unit of pixels.
HeightCM { get; set; }Represents the height of the comment, in unit of centimeters.
HeightInch { get; set; }Represents the height of the comment, in unit of inches.
HtmlNote { get; set; }Gets and sets the html string which contains data and some formats in this comment.
IsThreadedComment { get; }Indicates whether this comment is a threaded comment.
IsVisible { get; set; }Represents if the comment is visible or not.
Note { get; set; }Represents the content of comment.
Row { get; }Gets the row index of the comment.
TextHorizontalAlignment { get; set; }Gets and sets the text horizontal alignment type of the comment.
TextOrientationType { get; set; }Gets and sets the text orientation type of the comment.
TextVerticalAlignment { get; set; }Gets and sets the text vertical alignment type of the comment.
ThreadedComments { get; }Gets the list of threaded comments;
Width { get; set; }Represents the width of the comment, in unit of pixels.
WidthCM { get; set; }Represents the width of the comment, in unit of centimeters.
WidthInch { get; set; }Represents the width of the comment, in unit of inches.

Methods

NameDescription
Characters(int, int)Returns a Characters object that represents a range of characters within the comment text.
FormatCharacters(int, int, Font, StyleFlag)Format some characters with the font setting.
GetCharacters()(Obsolete.) Returns all Characters objects that represents a range of characters within the comment text.
GetRichFormattings()Returns all Characters objects that represents a range of characters within the comment text.

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using Aspose.Cells.Drawing;
    using System;

    public class CommentDemo
    {
        public static void CommentExample()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();
            // Access the first worksheet
            Worksheet worksheet = workbook.Worksheets[0];
            // Access the comments collection of the worksheet
            CommentCollection comments = worksheet.Comments;

            // Add a comment to cell A1
            int commentIndex1 = comments.Add(0, 0);
            Comment comment1 = comments[commentIndex1];
            comment1.Note = "First note.";
            comment1.Font.Name = "Times New Roman";
            comment1.Font.Size = 12;
            comment1.Font.Color = System.Drawing.Color.Red;
            comment1.Author = "Carl.Yang";
            comment1.HtmlNote = "<Font Style='FONT-FAMILY: Calibri;FONT-SIZE: 11pt;COLOR: #0000ff;TEXT-ALIGN: left;'>This is a <b>test</b>.</Font>";
            comment1.IsVisible = true;
            comment1.TextOrientationType = TextOrientationType.TopToBottom;
            comment1.TextHorizontalAlignment = TextAlignmentType.Center;
            comment1.TextVerticalAlignment = TextAlignmentType.Center;
            comment1.AutoSize = true;
            comment1.HeightCM = 1.0;
            comment1.WidthCM = 1.0;
            comment1.Width = 10;
            comment1.Height = 10;
            comment1.WidthInch = 1.0;
            comment1.HeightInch = 1.0;

            // Access the shape of the comment
            CommentShape shape = comment1.CommentShape;
            int w = shape.Width;
            int h = shape.Height;

            // Add a comment to cell B2
            comments.Add("B2");
            Comment comment2 = comments["B2"];
            comment2.Note = "Second note.";

            // Save the workbook
            workbook.Save("CommentExample.xlsx");
            workbook.Save("CommentExample.pdf");
        }
    }
}

See Also