Comments

Following sample demonstrates how to set 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.

Screenshot

Comments Screenshot

See the full code below, use RUN EXAMPLE to execute.


1using GemBox.Spreadsheet;
2using System;
3using System.IO;
4
5class Sample
6{
7    [STAThread]
8    static void Main(string[] args)
9    {
10        // If using Professional version, put your serial key below.
11        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
12
13        ExcelFile ef = new ExcelFile();
14        ExcelWorksheet ws = ef.Worksheets.Add("Comments");
15
16        ws.Cells[0, 0].Value = "Comment examples:";
17
18        ws.Cells[2, 1].Comment.Text = "Empty cell.";
19
20        ws.Cells[4, 1].Value = 5;
21        ws.Cells[4, 1].Comment.Text = "Cell with a number.";
22
23        ws.Cells["B7"].Value = "Cell B7";
24
25        ExcelComment comment = ws.Cells["B7"].Comment;
26        comment.Text = "Some formatted text.\nComment is:\na) multiline,\nb) large,\nc) visible, and \nd) formatted.";
27        comment.IsVisible = true;
28        comment.TopLeftCell = new AnchorCell(ws.Columns[3], ws.Rows[4], true);
29        comment.BottomRightCell = new AnchorCell(ws.Columns[5], ws.Rows[10], false);
30
31        // Get first 20 characters of a string
32        FormattedCharacterRange characters = comment.GetCharacters(0, 20);
33
34        // Apply color, italic and size to selected characters
35        characters.Font.Color = SpreadsheetColor.FromName(ColorName.Orange);
36        characters.Font.Italic = true;
37        characters.Font.Size = 300;
38
39        // Apply color to 'formatted' part of text
40        comment.GetCharacters(5, 9).Font.Color = SpreadsheetColor.FromName(ColorName.Red);
41
42        ef.Save("Comments.xlsx");
43    }
44}
1Imports GemBox.Spreadsheet
2Imports System.IO
3
4Module Samples
5
6    Sub Main()
7
8        ' If using Professional version, put your serial key below.
9        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")
10
11        Dim ef As ExcelFile = New ExcelFile
12        Dim ws As ExcelWorksheet = ef.Worksheets.Add("Comments")
13
14        ws.Cells.Item(0, 0).Value = "Comment examples:"
15
16        ws.Cells.Item(2, 1).Comment.Text = "Empty cell."
17
18        ws.Cells.Item(4, 1).Value = 5
19        ws.Cells.Item(4, 1).Comment.Text = "Cell with a number."
20
21        ws.Cells.Item("B7").Value = "Cell B7"
22
23        Dim comment As ExcelComment = ws.Cells("B7").Comment
24        comment.Text = "Some formatted text. Comment is:" & ChrW(10) & "a) multiline," & ChrW(10) & "b) large," & ChrW(10) & "c) visible, and " & ChrW(10) & "d) formatted."
25        comment.IsVisible = True
26        comment.TopLeftCell = New AnchorCell(ws.Columns(3), ws.Rows(4), True)
27        comment.BottomRightCell = New AnchorCell(ws.Columns(5), ws.Rows(10), False)
28
29        ' Get first 20 characters of a string
30        Dim characters As FormattedCharacterRange = comment.GetCharacters(0, 20)
31
32        ' Apply color, italic and size to selected characters
33        characters.Font.Color = SpreadsheetColor.FromName(ColorName.Orange)
34        characters.Font.Italic = True
35        characters.Font.Size = 300
36
37        ' Apply color to 'formatted' part of text
38        comment.GetCharacters(5, 9).Font.Color = SpreadsheetColor.FromName(ColorName.Red)
39
40        ef.Save("Comments.xlsx")
41
42    End Sub
43
44End Module

Check next sample or find out more about GemBox.Spreadsheet and GemBox Software.