python - 使用 Python 从 Excel (.xlsx) 中提取超链接

标签 python hyperlink xlrd openpyxl

我一直在关注用于 Excel 文件操作的 xlrd 和 openpyxl 库。但是,xlrd 目前不支持 .xlsx 文件的 formatting_info=True,所以我无法使用 xlrd hyperlink_map 函数。所以我转向 openpyxl,但也没有运气从 excel 文件中提取超链接。下面的测试代码(测试文件包含一个指向 google 的简单超链接,超链接文本设置为“test”):

import openpyxl

wb = openpyxl.load_workbook('testFile.xlsx')

ws = wb.get_sheet_by_name('Sheet1')

r = 0
c = 0

print ws.cell(row = r, column = c). value
print ws.cell(row = r, column = c). hyperlink
print ws.cell(row = r, column = c). hyperlink_rel_id

输出:

test

None

我猜openpyxl目前也不完全支持格式化?是否有其他库可用于从 Excel (.xlsx) 文件中提取超链接信息?

最佳答案

这可以通过 openpyxl 实现:

import openpyxl

wb = openpyxl.load_workbook('yourfile.xlsm')
ws = wb['Sheet1']
# This will fail if there is no hyperlink to target
print(ws.cell(row=2, column=1).hyperlink.target)

关于python - 使用 Python 从 Excel (.xlsx) 中提取超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16676727/

相关文章:

html - 页面顶部区域不可点击

python - 如何从Excel中提取指定行而不使用NaN

python - 使用python在excel中的单元格的多选选项

python - 在 Python 2.7 中为列表中的变量赋值

Python认为我是不同的IP

git - 如何在同一存储库的 README Markdown 文件中显示(链接到/超链接)Azure DevOps Git 存储库中的图像?

html 基础和子目录

Python pandas 将行插入 DF 并将缺失值作为 Nan 的快速方法

python - python 中的父 __unicode__

python - 在 Pandas/Pyspark 中比较 2 个数据帧、分配标签并拆分行