从Excel文档中获取超链接URL

Aam*_*nan 10 python xlrd

我正在使用xlrd读取Excel文件.在一列中,我有一个公司名称,其格式为超链接(意味着它背后有一个URL).当我得到单元格值时,我只得到公司名称.我怎样才能获得它背后的URL?

下面是使用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??
Run Code Online (Sandbox Code Playgroud)

phi*_*hag 8

在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)
Run Code Online (Sandbox Code Playgroud)