So how to make comment in excel with C#, VB.NET is the main point in this article. The whole procedure can be very easy since I use an excel creation component Spire.XLS to help me. You also can Freely Install Spire.XLS on the system.
How to add Excel comment with C#, VB.NET
Using Spire.XLS, I only need three steps to realize this task in a quick way. Please look at the below procedure.
Step1. Load an Excel file from System.
C# Code:
//Load File
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"D:\michelle\e-iceblue\Spire.XLS\Demos\Data\comment.xlsx");
Worksheet sheet = workbook.Worksheets[0];
VB.NET Code:
'Load File
Dim workbook As New Workbook()
workbook.LoadFromFile("D:\michelle\e-iceblue\Spire.XLS\Demos\Data\comment.xlsx")
Dim sheet As Worksheet = workbook.Worksheets(0)
Step2. Add comment in Excel.
C# Code:
//Add Comment
string str = "E-mail has been changed as [email protected]";
ExcelFont font1 = workbook.CreateFont();
font1.FontName = "Century Gothic";
font1.Color = Color.DarkCyan;
font1.IsBold = true;
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);
VB.NET Code:
'Add Comment
Dim str As String = "E-mail has been changed as [email protected]"
Dim font1 As ExcelFont = workbook.CreateFont()
font1.FontName = "Century Gothic"
font1.Color = Color.DarkCyan
font1.IsBold = True
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)
C# Code:
//Save and Launch
workbook.SaveToFile("Comment.xlsx", ExcelVersion.Version2010);
System.Diagnostics.Process.Start("Comment.xlsx");
VB.NET Code:
'Save and Launch
workbook.SaveToFile("Comment.xlsx", ExcelVersion.Version2010)
System.Diagnostics.Process.Start("Comment.xlsx")
Note: 1. Please choose .NET Framework4 as the Target framework.
2. Add Spire.XLS DLL and System.Drawing as references.
3. Add the following using at the top of the file.
C#
using System.Drawing;
using Spire.Xls;
using Spire.Xls.Core;
Preview
There are many other Excel functions that can be realized by C#, VB.NET. So if you want to consult more, please see below:
More Excel Functions