This support get cell hyperlink for merged cells

This commit is contained in:
xuri 2023-03-29 00:00:27 +08:00
parent 9dbba9f34a
commit 3b807c4bfe
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
3 changed files with 22 additions and 21 deletions

View File

@ -801,12 +801,13 @@ func (f *File) GetCellHyperLink(sheet, cell string) (bool, string, error) {
if err != nil {
return false, "", err
}
if cell, err = f.mergeCellsParser(ws, cell); err != nil {
return false, "", err
}
if ws.Hyperlinks != nil {
for _, link := range ws.Hyperlinks.Hyperlink {
if link.Ref == cell {
ok, err := f.checkCellInRangeRef(cell, link.Ref)
if err != nil {
return false, "", err
}
if link.Ref == cell || ok {
if link.RID != "" {
return true, f.getSheetRelationshipsTargetByID(sheet, link.RID), err
}

View File

@ -87,7 +87,7 @@ func TestDataValidation(t *testing.T) {
dataValidations, err = f.GetDataValidations("Sheet1")
assert.NoError(t, err)
assert.Len(t,dataValidations, 3)
assert.Len(t, dataValidations, 3)
// Test get data validation on no exists worksheet
_, err = f.GetDataValidations("SheetN")

View File

@ -480,7 +480,7 @@ func TestGetCellHyperLink(t *testing.T) {
ws, ok = f.Sheet.Load("xl/worksheets/sheet1.xml")
assert.True(t, ok)
ws.(*xlsxWorksheet).MergeCells = &xlsxMergeCells{Cells: []*xlsxMergeCell{{Ref: "A:A"}}}
ws.(*xlsxWorksheet).Hyperlinks = &xlsxHyperlinks{Hyperlink: []xlsxHyperlink{{Ref: "A:A"}}}
link, target, err = f.GetCellHyperLink("Sheet1", "A1")
assert.EqualError(t, err, newCellNameToCoordinatesError("A", newInvalidCellNameError("A")).Error())
assert.Equal(t, link, false)