Reputation: 811
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.
Upvotes: 0
Views: 2176
Reputation: 8421
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.
Upvotes: 1