Insert Cell Comments to Excel programmatically in C#.NET
Error processing SSI file

How to Add Comment to Excel in C#.NET Code


Insert text comment to spreadsheet, sinle line and multi-line comment are both supported. Comments are notes that can be inserted into any Cell in Excel. Comments are very useful for reminders & notes for others subject.

How to Insert Cell Comment to Spreadsheet in C# language

This C# tutorial shows how to create cell comment in Excel .xlsx file.

Create Single Line Comment

Add simple comment to cell "A1".

worksheet.Cell("A1").Comment.AddText("Single line comment."); 

Create Multiple Lines Comment

Inserting multi-line comments to worksheet is available using RichString property, allows to change comment font style, font size and font name.

var comment = worksheet.Cell("A2").Comment; comment.AddText("Frist line in comment.").SetBold().SetFontSize(6); comment.AddNewLine(); comment.AddText("Sencond line.").FontName = "Times New Roman"; 

Format Comment

If there is a long text line in the comment, you can set AutomaticSize property as ture to show this long text as one line, or keey the long text wrap automatically.

comment = worksheet.Cell("A3").Comment; comment.AddText("This is a very very very very very long line comment."); comment.Style.Size.AutomaticSize = true; 

Set comment size and position. The position is available only when the comment is visible.

comment.Style.Size.Height = 100; comment.Style.Size.Width = 10; comment.Position.Column = 5; comment.Position.Row = 5; //The position is available only when the comment is visible. comment.Visible = true; 

Change comment font color, you can use the pre-defined color, color from argb, color from Html code.

comment.AddText("This").FontColor = ExcelColor.Red; comment.AddText(" is").FontColor = ExcelColor.FromArgb(0, 0, 128, 0); comment.AddText(" colorful").FontColor = ExcelColor.FromHtml("#987654"); comment.AddText(" line.").FontColor = ExcelColor.Black; 

Full code for adding a Excel comment in C#

var workbook = new Workbook(); var worksheet = workbook.Worksheets.Add("CommentSheet"); //Add simple comment worksheet.Cell("A1").Comment.AddText("Single line comment."); //Add multiple lines comment var comment = worksheet.Cell("A2").Comment; comment.AddText("Frist line in comment.").SetBold().SetFontSize(6); comment.AddNewLine(); comment.AddText("Sencond line.").FontName = "Times New Roman"; //Add auto fit width comment comment = worksheet.Cell("A3").Comment; comment.AddText("This is a very very very very very long line comment1."); comment.Style.Size.AutomaticSize = true; //Add target size comment comment = worksheet.Cell("A4").Comment; comment.AddText("This is a very very very very very long line comment2."); comment.Style.Size.Height = 100; comment.Style.Size.Width = 10; //Add target position comment comment = worksheet.Cell("A5").Comment; comment.AddText("This comment will be shown on E5."); comment.Position.Column = 5; comment.Position.Row = 5; //The position is available only when the comment is visible. comment.Visible = true; //Add colorful comment comment = worksheet.Cell("A6").Comment; comment.AddText("This").FontColor = ExcelColor.Red; comment.AddText(" is").FontColor = ExcelColor.FromArgb(0, 0, 128, 0); comment.AddText(" colorful").FontColor = ExcelColor.FromHtml("#987654"); comment.AddText(" line.").FontColor = ExcelColor.Black; workbook.Save("comment.xlsx"); 
What iDiTect .NET Document component can do

We provide powerful & profession document & image controls: The simplest way to convert Excel to PDF in C# .Net .NET application to convert Excel XLSX documents to PDF, the full C# source code for the demo application is available in the Samples folder. How to convert word to image file using c# for mvc web application You can convert Docx file to image using bellow code it worked for me. Create pivot table in excel using VB.Net and C# in ASP.Net C# demo to guide how to create PivotTable into .xlsx file programmatically in C# language. Convert Word File to PDF Using C# Convert Word file (DOCX) to PDF in C# and VB.NET with Converter component. The best C# HTML to PDF solution Everyone at some point needs to convert and html page into a PDF for some reason or another. Create Excel Tables from C# / VB.NET application Rows and columns of Excel sheet can be directly imported to data-set using C#, no need to open Excel file using INTEROP.

More Programming Tutorials
More Programming FAQs