[英]Getting a hyperlink URL from an Excel document
I am reading an Excel file using xlrd .我正在使用xlrd读取Excel 文件。 In one column I have a company name which is formatted as a hyperlink (meaning there is a URL behind it).
在一列中,我有一个公司名称,其格式为超链接(意味着它后面有一个 URL)。 When I get the cell value I only get the company name.
当我得到单元格值时,我只得到公司名称。 How can I also get the URL behind it?
怎么还能弄到后面的URL?
Below is the code for reading an Excel file using the xlrd module (assume files are imported).下面是使用 xlrd 模块读取 Excel 文件的代码(假设文件已导入)。
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??
In xlrd 0.7.2 or newer, you can use hyperlink_map
:在 xlrd 0.7.2 或更高版本中,您可以使用
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.