Getting a hyperlink URL from an Excel document

前端 未结 1 1366
星月不相逢
星月不相逢 2020-12-31 11:49

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

相关标签:
1条回答
  • 2020-12-31 12:14

    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)
    
    0 讨论(0)
提交回复
热议问题