0

I am reading an excel file in C#.NET. The data is being read successfully but there is problem with some hyperlinks stored in the excel file.

I can read their text but i dont know how to get the underlying link/url of the column.

I couldnt find much help on google as well. if someone has worked in a similar situation please let me know what can be done.

edit::: i am using OleDb namespace for establishing a connection with the Excel file so if someone can post a solution which applies to this situation please do.

1
  • How are you reading in the file? This will be important for helping find and fix the problem. Commented Sep 22, 2010 at 13:22

1 Answer 1

1

you can try some thing like this using Excel Interop

for (int i = 1; i <= sheet.UsedRange.Rows.Count; ++i)
{
    for (int j = 1; j <= sheet.UsedRange.Columns.Count; ++j)
    {
        Range rng = (Range)sheet.UsedRange[i, j];
        if (rng != null)
        {
            if(rng.Hyperlinks.Count > 0)
            {
                string url = rng.Hyperlinks[1].Address; // always throw an exception.
            }
        }
    }
}

EDIT: I dont think you can retrieve hyperlinks using Oledb. you could try reading the file into a text stream and look for link patterns in the stream.

Sign up to request clarification or add additional context in comments.

3 Comments

i m using oledbconnection so i think this is not applicable :(
Using Excel interop on a web server is not a good idea - see support.microsoft.com/kb/257757
usin excels is itself not a good idea in a web app :), but when you are forced to use it interop is as good as anything else

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.