从 Excel 文档中获取超链接 URL [英] Getting a hyperlink URL from an Excel document
本文介绍了从 Excel 文档中获取超链接 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Excel 文件阅读="http://pypi.python.org/pypi/xlrd" rel="noreferrer">xlrd.在一个列中,我有一个公司名称,它的格式为超链接(意味着它后面有一个 URL).当我获得单元格值时,我只能获得公司名称.我怎样才能获得它背后的网址?
I am reading an Excel file using xlrd. In one column I have a company name which is formatted as a hyperlink (meaning there is a URL behind it). When I get the cell value I only get the company name. How can I also get the URL behind it?
以下是使用 xlrd 模块读取 Excel 文件的代码(假设文件已导入).
Below is the code for reading an Excel file using the xlrd module (assume files are imported).
mainData_book = xlrd.open_workbook("IEsummary.xls", formatting_info=True)
mainData_sheet = mainData_book.sheet_by_index(0) # Get the first sheet 0
start = 1
end = 101
for counter in range(start, end):
rowValues = mainData_sheet.row_values(counter, start_colx=0, end_colx=8)
company_name = rowValues[0] #how i can get link here also??
推荐答案
在 xlrd 0.7.2 或更新版本中,您可以使用 hyperlink_map
:
In xlrd 0.7.2 or newer, you can use hyperlink_map
:
import xlrd
mainData_book = xlrd.open_workbook("IEsummary.xls", formatting_info=True)
mainData_sheet = mainData_book.sheet_by_index(0)
for row in range(1, 101):
rowValues = mainData_sheet.row_values(row, start_colx=0, end_colx=8)
company_name = rowValues[0]
link = mainData_sheet.hyperlink_map.get((row, 0))
url = '(No URL)' if link is None else link.url_or_path
print(company_name.ljust(20) + ': ' + url)
这篇关于从 Excel 文档中获取超链接 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文