显示插入“超链接"字段中的文本,但不充当链接 [英] Text inserted into Hyperlink field shows up but does not act as a link

查看:187
本文介绍了显示插入“超链接"字段中的文本,但不充当链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难让我的pyodbc插入超链接以在Access 2003数据库中工作.它看起来像一个超链接,但单击时不执行任何操作.为了使它起作用,我必须在Access中对其进行编辑,然后它才能识别出哦,是的,它是超链接".

I'm having difficulty getting my pyodbc inserted hyperlinks to work in my Access 2003 database. It appears to look like a hyperlink but does nothing when clicked on. For it to work, I have to edit it in Access and only then does it recognize that, "oh yeah that is a hyperlink".

import pyodbc

cnxn = pyodbc.connect("DRIVER={Microsoft Access Driver (*.mdb)};DBQ= C:\\Users\\multidata\\Documents\\db1.mdb;")

cur = cnxn.cursor()
#hyperlink is the text file. table1 is hyperlink column in ms access
cur.execute("INSERT INTO test(table1, table2) values ('C:\\Users\\multidata\\Desktop\\MC1\\7-31-14_711_EX_2153.txt ', 'y')")
cnxn.commit()
cnxn.close()

推荐答案

Access中的超链接"字段是一个文本字段,其中包含多个用散号(#)分隔的部分". MSDN文章此处.

A Hyperlink field in Access is a text field containing a number of "parts" separated by hash marks (#). Those various parts are described in the MSDN article here.

如果我们要将裸露的URL或file_path插入超链接"字段中,则需要将其用井号括起来,例如

If we want to insert a bare URL or file_path into a Hyperlink field we need to enclose it in hash marks, e.g.

import pyodbc
conn_str = (
    r'DRIVER={Microsoft Access Driver (*.mdb)};'
    r'DBQ=C:\Users\Public\a2003test.mdb;'
)
cnxn = pyodbc.connect(conn_str)
crsr = cnxn.cursor()
hyperlink = r'C:\Users\Gord\Desktop\foo.txt'
sql = "UPDATE Table1 SET docLink=? WHERE ID=1"
crsr.execute(sql, ['#'+hyperlink+'#'])
cnxn.commit()
crsr.close()
cnxn.close()

这篇关于显示插入“超链接"字段中的文本,但不充当链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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