Skip to content

SetCellHyperlink cannot set display value #790

@jrdallen97

Description

@jrdallen97

Description

The SetCellHyperlink method doesn't allow you to set the display value of the hyperlink. Instead, the library expects us to set the cell value separately to act as the link text. This works fine when using Excel or LibreOffice to view the generated xlsx, but Google Sheets only checks the hyperlink's display value when trying to get the cell text, and falls back to displaying the link location if unset. This means that excelize spreadsheets imported into Google Sheets display wrongly (see below).

GSheet link text not working

For some reason, this only seems to affect location hyperlinks and not external hyperlinks.

Opening the produced file in Excel, saving without making any changes, then importing into Google Sheets causes the link text to work, as Microsoft Excel will set the display value on the hyperlink when saving.


Steps to reproduce the issue:

  1. Create a simple spreadsheet that sets the value of a cell & sets it's hyperlink:
    f := excelize.NewFile()
    f.SetCellStr("Sheet1", "A1", "Location link text")
    f.SetCellHyperLink("Sheet1", "A1", "Sheet1!A5", "Location")
    f.SaveAs("demo.xlsx")
  1. Create a new google sheet, go to File -> Import -> Upload, and upload the produced demo.xlsx.

Describe the results you received:
The cell text is #gid=1908937434&range=A5 and the cell links to cell A5.

Describe the results you expected:
The cell text is Location link text and the cell links to cell A5.


Output of go version:

go version go1.16 darwin/amd64

Excelize version or commit ID:

v2.3.2

Environment details (OS, Microsoft Excel™ version, physical, etc.):
MacOS 11.1 (Big Sur)
Google Sheets
Excel Version: 16.16.27

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