Excel cell comments

The following example shows how to set Excel cell comment with location, text and visibility.

Sample also shows how to format individual characters and words within a comment text.

Comments reading/writing is supported in XLSX and ODS file formats.

Comments formatting is supported only in XLSX.

Excel cell comments set with GemBox.Spreadsheet
Screenshot of Excel cell comments set with GemBox.Spreadsheet
using GemBox.Spreadsheet;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

        var workbook = new ExcelFile();
        var worksheet = workbook.Worksheets.Add("Comments");

        worksheet.Cells[0, 0].Value = "Comment examples:";

        worksheet.Cells[2, 1].Comment.Text = "Empty cell.";

        worksheet.Cells[4, 1].Value = 5;
        worksheet.Cells[4, 1].Comment.Text = "Cell with a number.";

        worksheet.Cells["B7"].Value = "Cell B7";

        var comment = worksheet.Cells["B7"].Comment;
        comment.Text = "Some formatted text.\nComment is:\na) multiline,\nb) large,\nc) visible, and \nd) formatted.";
        comment.IsVisible = true;
        comment.TopLeftCell = new AnchorCell(worksheet.Columns[3], worksheet.Rows[4], true);
        comment.BottomRightCell = new AnchorCell(worksheet.Columns[5], worksheet.Rows[10], false);

        // Get first 20 characters of a string.
        var characters = comment.GetCharacters(0, 20);

        // Apply color, italic and size to selected characters.
        characters.Font.Color = SpreadsheetColor.FromName(ColorName.Orange);
        characters.Font.Italic = true;
        characters.Font.Size = 300;

        // Apply color to 'formatted' part of text.
        comment.GetCharacters(5, 9).Font.Color = SpreadsheetColor.FromName(ColorName.Red);

        workbook.Save("Comments.%OutputFileType%");
    }
}
Imports GemBox.Spreadsheet

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")

        Dim workbook = New ExcelFile
        Dim worksheet = workbook.Worksheets.Add("Comments")

        worksheet.Cells.Item(0, 0).Value = "Comment examples:"

        worksheet.Cells.Item(2, 1).Comment.Text = "Empty cell."

        worksheet.Cells.Item(4, 1).Value = 5
        worksheet.Cells.Item(4, 1).Comment.Text = "Cell with a number."

        worksheet.Cells.Item("B7").Value = "Cell B7"

        Dim comment = worksheet.Cells("B7").Comment
        comment.Text = "Some formatted text. Comment is:" & ChrW(10) & "a) multiline," & ChrW(10) & "b) large," & ChrW(10) & "c) visible, and " & ChrW(10) & "d) formatted."
        comment.IsVisible = True
        comment.TopLeftCell = New AnchorCell(worksheet.Columns(3), worksheet.Rows(4), True)
        comment.BottomRightCell = New AnchorCell(worksheet.Columns(5), worksheet.Rows(10), False)

        ' Get first 20 characters of a string.
        Dim characters = comment.GetCharacters(0, 20)

        ' Apply color, italic and size to selected characters.
        characters.Font.Color = SpreadsheetColor.FromName(ColorName.Orange)
        characters.Font.Italic = True
        characters.Font.Size = 300

        ' Apply color to 'formatted' part of text.
        comment.GetCharacters(5, 9).Font.Color = SpreadsheetColor.FromName(ColorName.Red)

        workbook.Save("Comments.%OutputFileType%")
    End Sub
End Module

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Spreadsheet yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.