Python - Win32Com - 如何从 Excel 电子表格单元格中提取超链接?

Posted

技术标签:

【中文标题】Python - Win32Com - 如何从 Excel 电子表格单元格中提取超链接?【英文标题】:Python - Win32Com - How to extract hyperlink from Excel spreadsheet cell? 【发布时间】:2012-05-14 14:53:20 【问题描述】:

我正在尝试使用以下代码从 Excel 电子表格中的各个单元格获取超链接:

import win32com.client 
import win32ui

app = win32com.client.Dispatch("Excel.Application") 
app.visible = True

workbook = app.Workbooks.Open("test.xlsx")
sheet = workbook.Sheets[0]
test_cell = sheet.Range("A8").value

这将打印以下内容:

test_cell
u'Link title'

但是当我尝试提取超链接时,它没有返回字符串格式的链接/url,而是返回一个“未知的 COMObject”:

test_cell = sheet.Range("A8").Hyperlinks
test_cell
<COMObject <unknown>>

【问题讨论】:

【参考方案1】:
sheet.Range("A8").Hyperlinks.Item(1).Address

【讨论】:

以上是关于Python - Win32Com - 如何从 Excel 电子表格单元格中提取超链接?的主要内容,如果未能解决你的问题,请参考以下文章