超链接不会显示 显示正确的文本
我正在尝试向单元格添加超链接以打开文件夹,下面的代码使超链接位于正确的单元格中,单击时会重定向到正确的文件夹,但它不会显示文本,而是显示文件夹名称,例如(: C:\Documents and Settings\abulle\Desktop\Python-Stuff\Spec-Load\Formatted\) 而不是“文件夹”
sheet.Hyperlinks.Add( Anchor = sheet.Cells(7,21), Address = "C:\\Python-Stuff\\Spec-Load\\Formatted\\" , TextToDisplay = "Folder")
I am trying to add a hyperlink to a cell to open a folder the code below makes the hyperlink in the proper cell and is when clicked redirects to the proper folder but it does not display the text provided it instead displays the folder name e.g. (:C:\Documents and Settings\abulle\Desktop\Python-Stuff\Spec-Load\Formatted\) instead of 'Folder'
sheet.Hyperlinks.Add( Anchor = sheet.Cells(7,21), Address = "C:\\Python-Stuff\\Spec-Load\\Formatted\\" , TextToDisplay = "Folder")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有一个权宜之计,一个拼凑的答案。我现在没有时间寻找更好的答案。如果这是我日常工作的一部分,我会花时间了解发生了什么。
我遇到了同样的问题(Excel 将链接地址显示为单元格文本,而不是
Hyperlinks.Add()
上提供的TextToDisplay
值)我的代码在单元测试下工作当通过运行 Python 2.7 解释器调用时 -
'TextToDisplay'
参数的值显示在单元格中。 “生产”代码(使用py2exe
构建)显示超链接。我会找出为什么有一天(这是低后台工作。)Hyperlinks.Add
返回刚刚添加的Hyperlink
对象。解决方法是检查该对象的TextToDisplay
属性 - 如果它不是我想要的,我会为其分配正确的值。I have a stopgap answer, a kludge. I don't have time at the moment to find a better answer. If this was part of my day job I'd spend the time to find out what's going on.
I've had the same issue (Excel shows the link address as the cell text instead of the
TextToDisplay
value supplied onHyperlinks.Add()
)My code works under unit test when invoked by running the Python 2.7 interpreter - the value of the
'TextToDisplay'
argument is displayed in the cell. The 'production' code (built usingpy2exe
) displays the hyperlink. I'll find out why some day (this is low background work.)Hyperlinks.Add
returns theHyperlink
object it just added. The workaround is to examine theTextToDisplay
property of that object - if it's not what I want, I assign the correct value to it.试试这个
try this