Adding cell comments in Excel spreadsheet was first introduced in Excel 97. Cell comments enable Excel developers to explain remind or inform the content of a cell or range of cells. Excel spreadsheet allows author to add cell comments as cell description which can help users to understand complex logic and know the data cells more deeply. There are many methods to add cell comments. This post will show you add cell comments through C#.
How to Add Cell Comments via C#?
Use C# to add cell comments can be very easy through the help of Spire.XLS, a professional .NET/Silverlight XLS component.
Download Spire.XLS Here
Ensure Spire.XLS and Visual Studio correctly installed on system. Follow the simple guide below to add cell comments via C#.
Step 1 Create Project
Create a C#/VB.NET project in your visual studio. Add Spire.XLS.dll as reference. The default setting of Spire.Xls.dll is placed under “C:\Program Files\e-iceblue\Spire.Xls\Bin”. Select assembly Spire.Xls.dll and click OK to add it to the project.
static void Main(string args)
Step 2 Load Excel File
Put the Excel file which we want to add cell comments into the project folder. Use the following code to load it into the project.
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets;
Step 3 Add Cell Comments
By using Spire.XLS, we can add cell comments with styles. We can set text comments with different font and color.
string str = "E-mail has been changed as firstname.lastname@example.org";
ExcelFont font1 = workbook.CreateFont();
font1.FontName = "Century Gothic";
font1.Color = Color.DarkCyan;
font1.IsBold = true;
After set text style, then add cell comments. Select cells range which we want to add comments. In addition, with Spire.XLS, users can even set comments area size.
sheet.Range["A6"].Comment.RichText.Text = str;
sheet.Range["A6"].Comment.Width = 200;
sheet.Range["A6"].Comment.Height = 50;
sheet.Range["A6"].Comment.RichText.SetFont(26, 47, font1);
Step 4 Save and Preview
Start the project and preview the effect.
Spire.XLS is a professional Excel component which enables developers/programmers to fast generate, read, write and modify Excel document for .NET and Silverlight. It supports C#, VB.NET, ASP.NET, ASP.NET MVC and Silverlight. Click to learn more…