Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can ADO be used to insert hyperlinks into Excel?

Posted on 2008-10-18
6
Medium Priority
?
1,308 Views
Last Modified: 2013-12-17
Hi,

I am exporting data from an SQL database into an existing excel file using C# and ADO.
I need to export a datatable where one of the columns is a hyperlink. I am using an OleDb update command to get the data in.


Can this be done?

So far I have tried writing the whole thing using interop but  i find it very 'clunky' and anyway I cannot get Excel installed on the server so thats out the question.

Code snippet attached.


int i=6;
            foreach (DataRow Row in BookiesData.Tables[0].Rows)
            {
               //I have an OleDB update command in here like:
 
  UPDATE [Sheet1$] SET [F5] = Row[0], F6 = Row[1]
 
           //but obviously in a C# string.
           //Say for example that i want F6 to contain a hyperlink with the URL stored in Row[1]
 
i++
 
            };

Open in new window

0
Comment
Question by:dan_0
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 11

Expert Comment

by:Ramesh Srinivas
ID: 22756422
To create a hyperlink field insert the following string and dynamic data:

For example in vb.net  (shouldnt be hard in c#) assign the cell the value of:

"=HYPERLINK(""" & dr("Link") & """, ""Click to View"")"

You basically want to insert:

=HYPERLINK("http://www.experts-exchange.com","Click to View")

I think thats what you may be after.

regards.
0
 

Author Comment

by:dan_0
ID: 22760394
Hi, thanks for the reply. Thats exactly what I am doing currently and it doesn't work. Maybe there is some setting in the Excel file or connection string needed to make it work?

Here's my query (the / character escapes the next character)

SET [F7] = '" + "=hyperlink(\"" + Row["URL"].ToString() + "\",\"" + Row["BookieName"].ToString() + "\")"

Here is my connection string:

OleDbConnection oConn = new OleDbConnection();
            string filename = Server.MapPath("~/auto/spreadsheet.xls");
            oConn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
    Data Source=" + filename + @";Extended Properties=
    ""Excel 8.0;IMEX=1;HDR=YES;""";




When I open the excel file, the following string is in the cells:

=HYPERLINK("http://www.theurl.com","click here")

Any more help appreciated
0
 
LVL 11

Expert Comment

by:Ramesh Srinivas
ID: 22765176
Try this....

1) Click on the cell
2) Then hit return

Does the cell change to a hyperlink?

thx.
0
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 
LVL 11

Expert Comment

by:Ramesh Srinivas
ID: 22765178
Also, please check that there are no spaces before the = sign.

thx.
0
 

Accepted Solution

by:
dan_0 earned 0 total points
ID: 22779676
Hi,

thanks for the replies

In answer to:

Try this....
1) Click on the cell
2) Then hit return
Does the cell change to a hyperlink?

The answer is YES but obviously this is not acceptable ultimately, it just shows that the outputted string is correct.

HOWEVER I HAVE FOUND A SOLUTION THAT SUITS ME

Output the URL and link text as a string to another hidden cell (e.g. F100 and F101)

And use this formula in the cell where you want the hyperlink

=hyperlink(F100,F101)

Works for me.

Cheers
0
 
LVL 11

Expert Comment

by:Ramesh Srinivas
ID: 22783845
"The answer is YES but obviously this is not acceptable ultimately"

The reason I asked this was because I have had in the past, the same issue and I am trying to remember how I solved it.

But you seem to have worked something out for yourself.

ALl the best.
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question