C#-Read Hyperlink from Excel

In the last post, I have shown the method to write hyperlink in Excel worksheet. But if I want to read hyperlinks in this Excel file to a textbox without opening it, how to do?

Now, this post focuses on how to read hyperlink from Excel by using C#.

At first, create a new Windows Form Application Project and name it ReadHyperlink. Secondly, create a form and name it, then design. In the form. I add one label at the top of form as a title. Add another two labels to point out which the text boxes will show. Add two text boxes following by cue words. Finally, add a button for reading.

Then, we can find a well designed form as following.

OK, double click Read and write code for realizing my requirement.

Also, I use Spire.XLS in this method, therefore, add dll file as reference firstly. Next, use the following code.

using System;

using System.Windows.Forms;

using Spire.Xls;

namespace ReadHyperlink

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            //Get Excel File with Hyperlink

            Workbook workbook = new Workbook();

            workbook.LoadFromFile(@”..\..\..\..\..\My Documents\sample.xls”);

            Worksheet sheet = workbook.Worksheets[0];

            //Read Hyperlink to TextBox

            textBox1.Text = sheet.HyperLinks[0].Address;

            textBox2.Text = sheet.HyperLinks[1].Address;

        }

    }

}

Result:

———————————————————————————————————————————–

Click Here to learn more about Spire.XLS.

Click Here to download Spire.XLS.

Advertisements

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