Excel comment is for people to make notes about additional data information and commonly is used to remind the author to modify data values. Thus, the comment becomes superfluous when the author already altered cells information. And sometimes when things vary again before the author modifies the information, we have to change the comment in time. In such cases, people need to remove and change the excel comment in a quick way.
Spire.XLS enables people not only to add comment but also to remove and change them with C#, VB.NET in an easy way. Below I will share with you how to remove and change Excel comment with C#, VB.NET by Freely using Spire.XLS.
Spire.XLS enables people not only to add comment but also to remove and change them with C#, VB.NET in an easy way. Below I will share with you how to remove and change Excel comment with C#, VB.NET by Freely using Spire.XLS.
How to remove and change Excel comment with C#, VB.NET
Using Spire.XLS, you only need four simple steps to realize these two functions. Please see the procedure.
Step1. Create a new project.
1. Create a new project in Visual Studio, and set the Target framework to be .NET Framework 4 in Properties.
2. Add Spire.XLS DLL as reference in Project.
3. Add below using at the top of the method.
C#
using Spire.Xls;
using Spire.Xls.Collections;
VB.NET
Imports Spire.Xls
Imports Spire.Xls.Collections
Step2. Load an Excel file from the system.
C# Code:
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"D:\e-iceblue\comment.xlsx", ExcelVersion.Version2010);
VB.NET Code:
Dim workbook As New Workbook()
workbook.LoadFromFile("D:\e-iceblue\comment.xlsx", ExcelVersion.Version2010)
C# Code:
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"D:\e-iceblue\comment.xlsx", ExcelVersion.Version2010);
VB.NET Code:
Dim workbook As New Workbook()
workbook.LoadFromFile("D:\e-iceblue\comment.xlsx", ExcelVersion.Version2010)
Step3. Remove and change the comment.
In this step, I use “workbook.Worksheets[0].Comments[1].Remove();”to remove comment.
Please note: Comment [1] means the second comment you insert, not the first. For example, I insert
the first comment in A8
the second comment in A5
Comment[0] means the comment in A8.
Comment[1] means the comment in A5.
C# Code:
//remove comment
workbook.Worksheets[0].Comments[1].Remove();
//change comment
ExcelComment comment0 = workbook.Worksheets[0].Comments[0];
Comment0.Text = "The Sales Manager is Stephenchy";
VB.NET Code:
'remove comment
workbook.Worksheets(0).Comments(1).Remove()
'change comment
Dim comment0 As ExcelComment = workbook.Worksheets(0).Comments(0)
Comment0.Text = "The Sales Manager is Stephenchy"
In this step, I use “workbook.Worksheets[0].Comments[1].Remove();”to remove comment.
Please note: Comment [1] means the second comment you insert, not the first. For example, I insert
the first comment in A8
the second comment in A5
Comment[0] means the comment in A8.
Comment[1] means the comment in A5.
C# Code:
//remove comment
workbook.Worksheets[0].Comments[1].Remove();
//change comment
ExcelComment comment0 = workbook.Worksheets[0].Comments[0];
Comment0.Text = "The Sales Manager is Stephenchy";
VB.NET Code:
'remove comment
workbook.Worksheets(0).Comments(1).Remove()
'change comment
Dim comment0 As ExcelComment = workbook.Worksheets(0).Comments(0)
Comment0.Text = "The Sales Manager is Stephenchy"
Step4. Save and launch the file.
C# Code:
//save and launch the file
workbook.SaveToFile("test.xlsx", ExcelVersion.Version2010);
System.Diagnostics.Process.Start("test.xlsx");
VB.NET Code:
'save and launch the file
workbook.SaveToFile("test.xlsx", ExcelVersion.Version2010)
System.Diagnostics.Process.Start("test.xlsx")
Preview
Excel has more other functions, you can get more by using C#, VB.NET if you want, please see below:
More Excel Functions