This support get cell hyperlink for merged cells
This commit is contained in:
parent
9dbba9f34a
commit
3b807c4bfe
9
cell.go
9
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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue