Blog author:
Lacy | Posted on: 5/29/2012 | Category:
C# Blogs | Views: 1046 | Status:
[Member] |
Points: 75
|
Alert Moderator
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.
How to remove and change Excel comment information 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)
Step3. Remove and change the comment.1. 1. Remove excel comment
workbook.Worksheets[0].Comments[1].Remove();
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.
2. 2. Change excel comment
You can
change the comment by setting the "Comment0.Text "value in the below code.
ExcelComment
comment0 = workbook.Worksheets[0].Comments[0];
Comment0.Text = "xxx";
Remove and change comment information
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
two comments
Remove and Change Comment
IAccording to the excel comment marks, you can see that there are two comments in the first picture and the comment content in A8 can be seen clearly. While in the second picture, only one comment is left and comment in A8 has been changed.
Found interesting? Add this to: