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
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)
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