Spread Windows Forms 15.0
Spread Windows Forms 15.0 Product Documentation / Developer's Guide / Cells / Adding a Comment to a Cell
In This Topic
    Adding a Comment to a Cell
    In This Topic

    Spread for Winforms supports adding comments to cells in a worksheet. You can add a plain text comment or note by referring to Adding a Note to a Cell topic.

    Additionally, you can enable the EnhancedShapeEngine property to add a string or RichText instances by using the IRange.AddComment method.

    You can modify the added comment by using the IRange.Comment property. For example, the image below shows a default comment as well as a customized comment. The customized comment is set to always be visible and has shape properties such as background color, shape border style, and border color.

    You can also add threaded comments by using the IRange.AddCommentThreaded method. This feature is currently supported in XLSX export only.

     

    The following code shows how to set comments and threaded comments.

    C#
    Copy Code
    // Enable enhanced shape engine
    fpSpread1.Features.EnhancedShapeEngine = true;
                
    string username = "Admin" + ":";
                
    // Initilize richtext object
    GrapeCity.Spreadsheet.RichText richText = new GrapeCity.Spreadsheet.RichText(username + "\r\nThis is a rich text \r\nsupported comment");
    
    // Setting style
    GrapeCity.Spreadsheet.Font font = GrapeCity.Spreadsheet.Font.Empty;
    font.Bold = true;
    GrapeCity.Spreadsheet.Font font2 = GrapeCity.Spreadsheet.Font.Empty;
    font2.Italic = true;
    font2.Underline = GrapeCity.Spreadsheet.UnderlineStyle.Double;
    
    // Adding style to rich text
    richText.Format(0, username.Length, font);
    richText.Format(17, 9, font2);
    
    // Adding a comment to cell
    GrapeCity.Spreadsheet.IComment comment = TestActiveSheet.Cells["B2"].AddComment(richText);
                
    // Customizing comment style
    TestActiveSheet.Cells["B2"].Comment.Visible = true; // Always show comment
    TestActiveSheet.Cells["B2"].Comment.Shape.Fill.BackColor.ARGB = Color.Orange.ToArgb();  // Change comment background color
    TestActiveSheet.Cells["B2"].Comment.Shape.Line.Style = GrapeCity.Drawing.LineStyle.ThickThin;   // Change border style
    TestActiveSheet.Cells["B2"].Comment.Shape.Line.Weight = 5;  // Change border thickness
    TestActiveSheet.Cells["B2"].Comment.Shape.Line.ForeColor.ARGB = Color.DeepSkyBlue.ToArgb(); // Change border color
    
    // Adding a threaded comment
    TestActiveSheet.Cells["C5"].AddCommentThreaded("Threaded comment supported");
    
    // Exporting a file containing threaded comment
    fpSpread1.SaveExcel("threaded-comment.xlsx", FarPoint.Excel.ExcelSaveFlags.UseOOXMLFormat | FarPoint.Excel.ExcelSaveFlags.Exchangeable);
    
    Visual Basic
    Copy Code
    'Enable enhanced shape engine
    FpSpread1.Features.EnhancedShapeEngine = True
    
    Dim username As String = "Admin" & ":"
    
    'Initilize richtext object
    Dim richText As GrapeCity.Spreadsheet.RichText = New GrapeCity.Spreadsheet.RichText(username & vbCrLf & "This is a rich text " & vbCrLf & "supported comment")
    
    'Setting style
    Dim font As GrapeCity.Spreadsheet.Font = GrapeCity.Spreadsheet.Font.Empty
    font.Bold = True
    Dim font2 As GrapeCity.Spreadsheet.Font = GrapeCity.Spreadsheet.Font.Empty
    font2.Italic = True
    font2.Underline = GrapeCity.Spreadsheet.UnderlineStyle.Double
    
    'Adding style to rich text
    richText.Format(0, username.Length, font)
    richText.Format(17, 9, font2)
    
    'Adding a comment to cell
    Dim comment As GrapeCity.Spreadsheet.IComment = TestActiveSheet.Cells("B2").AddComment(richText)
    
    'Customizing comment style
    TestActiveSheet.Cells("B2").Comment.Visible = True  'Always show comment
    TestActiveSheet.Cells("B2").Comment.Shape.Fill.BackColor.ARGB = Color.Orange.ToArgb()   'Change comment background color
    TestActiveSheet.Cells("B2").Comment.Shape.Line.Style = GrapeCity.Drawing.LineStyle.ThickThin    'Change border style
    TestActiveSheet.Cells("B2").Comment.Shape.Line.Weight = 5   'Change border thickness
    TestActiveSheet.Cells("B2").Comment.Shape.Line.ForeColor.ARGB = Color.DeepSkyBlue.ToArgb()  'Change border color
    
    'Adding a threaded comment
    TestActiveSheet.Cells("C5").AddCommentThreaded("Threaded comment supported")
    
    'Exporting a file containing threaded comment
    FpSpread1.SaveExcel("threaded-comment.xlsx", FarPoint.Excel.ExcelSaveFlags.UseOOXMLFormat Or FarPoint.Excel.ExcelSaveFlags.Exchangeable)