Add Comments in Excel and Set Comments Format in C#, VB.NET

Excel comment is added especially when the cell information is changed or need some additional notice. When we manually add comments in excel, it is such easy. While how about add excel comments programmatically? Could we set excel comment format in C#, VB.NET? The answer is absolutely YES. Now let us go to the main solution.

Excel comment will be quickly added as a string by this .NET Excel component Spire.XLS for .NET. Then, using ExcelFont which is a class in Spire.Xls, we can set comment format such as font, color, bold. In order to fit the comment perfectly, we can use another class Spire.Xls.RichText to set the text box size. Finally, when we want to highlight the special text in comment we can call this method: ExcelComment.RichText.SetFont(int startPos, int endPos, ExcelFont font). Now please see the comment effect as below picture:

Add Excel Comments

Here you can download Spire.XLS for .NET and install it on your system. After adding Spire.Xls dll, you can follow below solution to add comments in Excel.

[C#]
String str = "E-mail has been changed as evanece@hotmail.com";
            ExcelFont font1 = workbook.CreateFont();
            font1.FontName = "Calibri";
            font1.Color = Color.Firebrick;
            font1.IsBold = true;
            sheet.Range["C6"].Comment.RichText.Text = str;
            sheet.Range["C6"].Comment.Width = 200;
            sheet.Range["C6"].Comment.Height = 50;
            sheet.Range["C6"].Comment.RichText.SetFont(26, 45, font1);
[VB.NET]
Dim str As String = "E-mail has been changed as evanece@hotmail.com"
Dim font1 As ExcelFont = workbook.CreateFont()
font1.FontName = "Calibri"
font1.Color = Color.Firebrick
font1.IsBold = True
sheet.Range("C6").Comment.RichText.Text = str
sheet.Range("C6").Comment.Width = 200
sheet.Range("C6").Comment.Height = 50
sheet.Range("C6").Comment.RichText.SetFont(26, 45, font1)