-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvpagebreaks.go
More file actions
98 lines (76 loc) · 1.74 KB
/
vpagebreaks.go
File metadata and controls
98 lines (76 loc) · 1.74 KB
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
92
93
94
95
96
97
98
package goxcel
import (
"github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
)
type (
VPageBreaks struct {
goxcelObj GoxcelObject
comObj *ole.IDispatch
}
)
func newVPageBreaks(goxcelObj GoxcelObject, comObj *ole.IDispatch) *VPageBreaks {
vpbs := new(VPageBreaks)
vpbs.goxcelObj = goxcelObj
vpbs.comObj = comObj
vpbs.Releaser().Add(func() error {
vpbs.ComObject().Release()
return nil
})
return vpbs
}
func NewVPageBreaks(ws *Worksheet, comObj *ole.IDispatch) *VPageBreaks {
return newVPageBreaks(ws, comObj)
}
func (vpbs *VPageBreaks) Goxcel() *Goxcel {
return vpbs.goxcelObj.Goxcel()
}
func (vpbs *VPageBreaks) Releaser() *Releaser {
return vpbs.Goxcel().Releaser()
}
func (vpbs *VPageBreaks) ComObject() *ole.IDispatch {
return vpbs.comObj
}
func (vpbs *VPageBreaks) Add(ra *XlRange) error {
_, err := oleutil.CallMethod(vpbs.ComObject(), "Add", ra.ComObject())
if err != nil {
return err
}
return nil
}
func (vpbs *VPageBreaks) Count() (int32, error) {
v, err := oleutil.GetProperty(vpbs.ComObject(), "Count")
if err != nil {
return 0, err
}
count, ok := v.Value().(int32)
if !ok {
return 0, ValueCantConvertToInt
}
return count, nil
}
func (vpbs *VPageBreaks) Item(index int) (*VPageBreak, error) {
v, err := oleutil.GetProperty(vpbs.ComObject(), "Item", index)
if err != nil {
return nil, err
}
hpb := NewVPageBreak(vpbs, v.ToIDispatch())
return hpb, nil
}
func (vpbs *VPageBreaks) Walk(walkFn func(hpb *VPageBreak) error) (*VPageBreak, error) {
count, err := vpbs.Count()
if err != nil {
return nil, err
}
for i := 1; i <= int(count); i++ {
hpb, err := vpbs.Item(i)
if err != nil {
return nil, err
}
err = walkFn(hpb)
if err != nil {
return hpb, err
}
}
return nil, nil
}