adding hyperlinks in some cells openpyxl

后端 未结 4 1474
时光说笑
时光说笑 2021-01-04 01:09

I have to generate an excel with summary results. The results are included in a list. Some of the elements are values and some links.

I managed to generate the excel

相关标签:
4条回答
  • 2021-01-04 01:18

    Try this :

    sheet['A1'].hyperlink = "http://stackoverflow.com"
    sheet['A1'].value="StackOverflow"
    

    In my try this does not add the formatting that Excel puts with a hyperlink but the cell contents are more like the Excel hyperlink cell than I get with the HYPERLINK tag.

    0 讨论(0)
  • 2021-01-04 01:27

    If wanting to use Excel's built in hyperlink function directly, you can use the following to format as a link:

    '=HYPERLINK("{}", "{}")'.format(link, "Link Name")

    e.g. ws.cell(row=1, column=1).value = '=HYPERLINK("{}", "{}")'.format(link, "Link Name")

    0 讨论(0)
  • 2021-01-04 01:34

    This works for me:

    wbook.active['A8'].hyperlink = "http://www.espn.com"
    wbook.active['A8'].value = 'ESPN'
    wbook.active['A8'].style = "Hyperlink"
    
    0 讨论(0)
  • 2021-01-04 01:35

    This worked for me.

    sheet.column_dimensions["A"].width = 30
    sheet.cell(row=1, column=1).hyperlink = "http://www.espn.com"
    book.save('links.xlsx')
    
    0 讨论(0)
提交回复
热议问题