Vb .NET将超链接插入excel单元格 [英] Vb .NET inserting hyper link to excel cell

查看:102
本文介绍了Vb .NET将超链接插入excel单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在文件中插入超链接到excel单元格。



我尝试了什么:



我正在尝试使用此代码,但是当我检查超链接在单元格中但是在我编辑单元格之前没有激活时,一旦超链接插入excel,然后按输入。

我认为这是因为超链接是作为文本插入的。

任何人都可以帮助我吗?



Hi,
I would like to insert hyperlink to file into excel cell.

What I have tried:

I was trying use this code but once hyperlink is inserted to excel when I checking the hyperlink is in cell but not active until I edit the cell then press enter.
I think its happens because the hyperlink is inserted as a text.
Could anyone can help me ?

<pre>Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=EXCEL_DATA\2SV REARS RFT.xls;Extended Properties = ""Excel 12.0 Xml;HDR=YES"""
        'Create an INSERT INTO SQL statement
        Dim insertStatement As String = "INSERT INTO [" & NOWEEK.Text & "$] ([LINE], [Date], [Shift], [Frame Type], [Quantity], [Problem], [Weld Number], [Welder]) VALUES ('=HYPERLINK(C:\SMART" & FRAMETYPE.Text & ".xlsx)','" + datee.Text + "','" + CHOSESHIFT.Text + "','" + FRAMETYPE.Text + "'," + QUANTITY.Text + ",'" + PROBLEM.Text + "','" + WELDNUMBER.Text + "','" + WELDERNAME.Text + "')"
        'Create a connection object to connect to the Excel Workbook
        Dim connection As New OleDbConnection(connectionString)
        'Create a command object that will execute the insert statement
        Dim command As New OleDbCommand(insertStatement, connection)
        'Open the connection, execute the statement and close the connection
        connection.Open()
        command.ExecuteNonQuery()
        connection.Close()
        'Dispose of the connection and command objects
        connection.Dispose()
        command.Dispose()
        'Call the RefreshData routine so that you can see that data was indeed added.

推荐答案

([LINE],[Date],[Shift],[Frame Type],[Quantity],[Problem] ,[焊接编号],[焊工])价值('= HYPERLINK(C:\SMART& FRAMETYPE.Text& 。xlsx)',' + datee.Text + ',' + CHOSESHIFT.Text + ',' + FRAMETYPE.Text + ', + QUANTITY.Text + ,' + PROBLEM.Text + ',' + WELDNUMBER.Text + ',' + WELDERNAME.Text + ')
' 创建连接对象以连接到Excel工作簿
Dim connection As OleDbConnecti on(connectionString)
' 创建一个将执行insert语句的命令对象
Dim 命令作为 OleDbCommand(insertStatement ,连接)
' 打开连接,执行语句并关闭连接
connection.Open()
command.ExecuteNonQuery()
connection.Close()
' 处理连接和命令对象
connection.Dispose()
command.Dispose()
' 调用RefreshData例程,以便您可以看到确实添加了数据。
([LINE], [Date], [Shift], [Frame Type], [Quantity], [Problem], [Weld Number], [Welder]) VALUES ('=HYPERLINK(C:\SMART" & FRAMETYPE.Text & ".xlsx)','" + datee.Text + "','" + CHOSESHIFT.Text + "','" + FRAMETYPE.Text + "'," + QUANTITY.Text + ",'" + PROBLEM.Text + "','" + WELDNUMBER.Text + "','" + WELDERNAME.Text + "')" 'Create a connection object to connect to the Excel Workbook Dim connection As New OleDbConnection(connectionString) 'Create a command object that will execute the insert statement Dim command As New OleDbCommand(insertStatement, connection) 'Open the connection, execute the statement and close the connection connection.Open() command.ExecuteNonQuery() connection.Close() 'Dispose of the connection and command objects connection.Dispose() command.Dispose() 'Call the RefreshData routine so that you can see that data was indeed added.


在简短:待能够添加超链接,你必须使用: Hyperlinks.Add方法(Excel) [ ^ ]。
In a short: to be able to add hyperlink, you have to use: Hyperlinks.Add Method (Excel)[^].


我检查一下,但这是在excel中创建宏。

我看的是添加超链接使用在vb .net。中创建的应用程序来优化单元格。
I check that but this is to create macro in excel.
What I looking is to add hyperlink to excel cell using application created in vb .net.


这篇关于Vb .NET将超链接插入excel单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆