-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhyperlinks.go
91 lines (70 loc) · 1.79 KB
/
hyperlinks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package goxcel
import (
"fmt"
"github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
)
type (
HyperLinks struct {
goxcelObj GoxcelObject
comObj *ole.IDispatch
}
)
func newHyperLinks(goxcelObj GoxcelObject, comObj *ole.IDispatch) *HyperLinks {
hl := new(HyperLinks)
hl.goxcelObj = goxcelObj
hl.comObj = comObj
hl.Releaser().Add(func() error {
hl.ComObject().Release()
return nil
})
return hl
}
func NewHyperLinks(ws *Worksheet, comObj *ole.IDispatch) *HyperLinks {
return newHyperLinks(ws, comObj)
}
func NewHyperLinksFromHyperLinks(hl *HyperLinks, comObj *ole.IDispatch) *HyperLinks {
return newHyperLinks(hl, comObj)
}
func (hl *HyperLinks) Goxcel() *Goxcel {
return hl.goxcelObj.Goxcel()
}
func (hl *HyperLinks) Releaser() *Releaser {
return hl.Goxcel().Releaser()
}
func (hl *HyperLinks) ComObject() *ole.IDispatch {
return hl.comObj
}
func (hl *HyperLinks) Add(ra *XlRange, address string, subAddress string, screenTip string, textToDisplay string) error {
_, err := oleutil.CallMethod(hl.ComObject(), "Add", ra.ComObject(), address, subAddress, screenTip, textToDisplay)
if err != nil {
return err
}
return nil
}
func (hl *HyperLinks) Item(index int) (*HyperLinks, error) {
if index <= 0 {
e := fmt.Errorf("%w [index]", ValueMustBeGreaterThanZero)
return nil, e
}
item, err := oleutil.GetProperty(hl.ComObject(), "Item", index)
if err != nil {
return nil, err
}
hl2 := NewHyperLinksFromHyperLinks(hl, item.ToIDispatch())
return hl2, nil
}
func (hl *HyperLinks) Count() (int64, error) {
count, err := oleutil.GetProperty(hl.ComObject(), "Count")
if err != nil {
return 0, err
}
return count.Val, nil
}
func (hl *HyperLinks) Delete() error {
_, err := oleutil.CallMethod(hl.ComObject(), "Delete")
if err != nil {
return err
}
return nil
}