Add Excel comment in C#, VB.NET
Syncfusion® Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents. It also, converts Excel documents to PDF files. Using this library, you can add Excel comments in C# and VB.NET.
What is the use of an Excel comment?
Excel comments are used to add notes to individual cells which explain the contents or offer tips to users. When a cell has a comment, a red triangle indicator appears in the upper-right corner of the cell. When you rest the pointer on the cell, the comment appears.
Steps to add Excel comments in C# and VB.NET programmatically:
Step 1: Create a new C# console application project.
Create a new C# console application
Step 2: Install the Syncfusion.XlsIO.WinForms NuGet package as reference to your .NET Framework application from NuGet.org.
Install NuGet package
Step 3: Include the following namespace in the Program.cs file.
C#
using Syncfusion.XlsIO;
VB.NET
Imports Syncfusion.XlsIO
Step 4: Use the following code snippet to add Excel comment in C#, VB.NET.
C#
using (ExcelEngine excelEngine = new ExcelEngine())
{
// Instantiate the Excel application object
IApplication application = excelEngine.Excel;// Add a workbook
IWorkbook workbook = application.Workbooks.Create(1);// The first worksheet object in the worksheets collection is accessed
IWorksheet worksheet = workbook.Worksheets[0];// Add cell texts
worksheet.Range["A1"].Text = "Cell containing regular Excel comment";
worksheet.Range["A3"].Text = "Cell containing rich-text Excel comment";// Add regular Excel comment
worksheet.Range["A1"].AddComment().Text = "Regular Excel comment";// Add rich-text Excel comment
IRange range = worksheet.Range["A3"];
range.AddComment().RichText.Text = "Excel comment with Rich-Text";
IRichTextString rtf = range.Comment.RichText;
IFont font = workbook.CreateFont();
font.Bold = true;
font.Italic = true;
rtf.SetFont(0, 4, font);// Save the workbook
workbook.SaveAs("Output.xlsx");
}
VB.NET
Using excelEngine As ExcelEngine = New ExcelEngine() ' Instantiate the Excel application object Dim application As IApplication = excelEngine.Excel ' Add a workbook Dim workbook As IWorkbook = application.Workbooks.Create(1) 'The first worksheet object in the worksheets collection is accessed Dim worksheet As IWorksheet = workbook.Worksheets(0) 'Add cell texts worksheet.Range("A1").Text = "Cell containing regular Excel comment" worksheet.Range("A3").Text = "Cell containing rich-text Excel comment" 'Add regular Excel comment worksheet.Range("A1").AddComment().Text = "Regular Excel comment" 'Add rich-text Excel comment Dim range As IRange = worksheet.Range("A3") range.AddComment().RichText.Text = "Excel comment with Rich-Text" Dim rtf As IRichTextString = range.Comment.RichText Dim font As IFont = workbook.CreateFont() font.Bold = True font.Italic = True rtf.SetFont(0, 4, font) 'Save the workbook workbook.SaveAs("Output.xlsx") End Using
A complete Windows Forms working example of how to add Excel comments in C# and VB.NET can be downloaded from Add Excel Comment.zip.
By executing the program, you will get the output Excel document as shown below.
Output Excel document
Refer here to explore the rich set of Syncfusion® Excel (XlsIO) library features.
See Also:
How to set RTF text to cell comment using XlsIO?
How to format comments in a cell using XlsIO
How to resize comment box using C#,VB.NET?
Create Excel comment with background image in C#, VB.NET
How to add text box shape in Excel charts?
Note:
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from a trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.
I hope you enjoyed learning about how to Add Excel comments in C#, VB.NET.
You can refer to our WinForms word feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms word example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!