Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 17645 |  Welcome, Guest!   Register  Login
 Home > Blogs > C# > Remove and Change Excel Comment Information with C#, VB.NET ...
Lacy

Remove and Change Excel Comment Information with C#, VB.NET

 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:


About Keating Arly

Experience:1 year(s)
Home page:http://www.e-iceblue.com
Member since:Tuesday, March 27, 2012
Level:Starter
Status: [Member]
Biography:
>> Write Response - Respond to this post and get points

More Blogs

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/19/2013 9:28:04 AM