Skip to content

Creating a hyperlink in a cell 🔗 #112

Open
@alemangui

Description

@alemangui

Hello, I can't seem find any documentation on how to add a hyperlink to a cell.

I've also tried looking for a post-process hook to see if I can manually add it with openpyxl but no success.

The only work around I could come up with is to make a custom renderer in which I add the hyperlinks, but this seems overkill and quite klunky (I'm loading the bytes, modifying the workbook, and then converting back to bytes) :

class HyperlinkXLSXRenderer(XLSXRenderer):
    def render(self, data, media_type=None, renderer_context=None):
        excel_data = super().render(data, media_type, renderer_context)
        workbook = load_workbook(filename=BytesIO(excel_data))

        for sheet in workbook.worksheets:
            for row in sheet.iter_rows(min_row=2): # Skip header
                row[0].hyperlink = "https://example.com"

        # Save back to bytes
        output = BytesIO()
        workbook.save(output)
        return output.getvalue()

Am I missing something obvious ? Is this adding a hyperlink a feature worth developing or documenting? How about a post-process hook?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions