How to Read Excel Comments and Display the Comments in TextBox with C#

Actually, the steps is similar the method to read hyperlink, which I have shared in my blog. Firstly, create a new Project named ReadComment.

Second, add dll file of one C# .NET Excel component, Spire.XLS for .NET, which is used to read comments with C# more quickly, as reference. 

Thirdly, design form to display comments.

  1. Create a form named ReadComment.
  2. Add a label on the top of form as a title to show which function we will realize.
  3. Add another two labels, Regular Comment and Rich Text Comment.
  4. Add a textbox following regular comment and a richtextbox following Rich Text Comment.
  5. Add a button to run code.

Then, the form has been completed.

ReadCommentDesign

Now, read the comments in customer.xlsx. Get comment range by using sheet.Range[] and read to text box with textBox.Text and richTextBox.Rtf.

using System;

using System.Windows.Forms;

using Spire.Xls;

 

namespace ReadComment

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            //Load Excel

            Workbook workbook = new Workbook();

            workbook.LoadFromFile(@”D:\Work\Customer.xlsx”);

 

            //Initialize worksheet

            Worksheet sheet = workbook.Worksheets[0];

            workbook.CreateEmptySheets(1);

 

            //Read Comment

            textBox1.Text = sheet.Range[“A3”].Comment.Text;

            richTextBox1.Rtf = sheet.Range[“A6”].Comment.RichText.RtfText;

        }

    }

}

Result:

Result

Download Spire.XLS for .NET Here

Advertisements

Author: janewdaisy

.NET Program Beginner. Share methods about how to use C#/VB.NET to export data, operate Word, Excel, PDF and other useful skills.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s