diff --git a/cell.go b/cell.go index 5fcadce..3f1e652 100644 --- a/cell.go +++ b/cell.go @@ -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 } diff --git a/datavalidation_test.go b/datavalidation_test.go index 6b70591..2f45fd9 100644 --- a/datavalidation_test.go +++ b/datavalidation_test.go @@ -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") diff --git a/excelize_test.go b/excelize_test.go index 6ff1fc4..f7afccc 100644 --- a/excelize_test.go +++ b/excelize_test.go @@ -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) @@ -1447,21 +1447,21 @@ func TestSetDefaultTimeStyle(t *testing.T) { } func TestAddVBAProject(t *testing.T) { - f := NewFile() - file, err := os.ReadFile(filepath.Join("test", "Book1.xlsx")) - assert.NoError(t, err) - assert.NoError(t, f.SetSheetProps("Sheet1", &SheetPropsOptions{CodeName: stringPtr("Sheet1")})) - assert.EqualError(t, f.AddVBAProject(file), ErrAddVBAProject.Error()) - file, err = os.ReadFile(filepath.Join("test", "vbaProject.bin")) - assert.NoError(t, err) - assert.NoError(t, f.AddVBAProject(file)) - // Test add VBA project twice - assert.NoError(t, f.AddVBAProject(file)) - assert.NoError(t, f.SaveAs(filepath.Join("test", "TestAddVBAProject.xlsm"))) - // Test add VBA with unsupported charset workbook relationships - f.Relationships.Delete(defaultXMLPathWorkbookRels) - f.Pkg.Store(defaultXMLPathWorkbookRels, MacintoshCyrillicCharset) - assert.EqualError(t, f.AddVBAProject(file), "XML syntax error on line 1: invalid UTF-8") + f := NewFile() + file, err := os.ReadFile(filepath.Join("test", "Book1.xlsx")) + assert.NoError(t, err) + assert.NoError(t, f.SetSheetProps("Sheet1", &SheetPropsOptions{CodeName: stringPtr("Sheet1")})) + assert.EqualError(t, f.AddVBAProject(file), ErrAddVBAProject.Error()) + file, err = os.ReadFile(filepath.Join("test", "vbaProject.bin")) + assert.NoError(t, err) + assert.NoError(t, f.AddVBAProject(file)) + // Test add VBA project twice + assert.NoError(t, f.AddVBAProject(file)) + assert.NoError(t, f.SaveAs(filepath.Join("test", "TestAddVBAProject.xlsm"))) + // Test add VBA with unsupported charset workbook relationships + f.Relationships.Delete(defaultXMLPathWorkbookRels) + f.Pkg.Store(defaultXMLPathWorkbookRels, MacintoshCyrillicCharset) + assert.EqualError(t, f.AddVBAProject(file), "XML syntax error on line 1: invalid UTF-8") } func TestContentTypesReader(t *testing.T) {