-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathshapes.go
93 lines (72 loc) · 1.65 KB
/
shapes.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
92
93
package goxcel
import (
"github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
)
type (
Shapes struct {
goxcelObj GoxcelObject
comObj *ole.IDispatch
}
)
func newShapes(goxcelObj GoxcelObject, comObj *ole.IDispatch) *Shapes {
shapes := new(Shapes)
shapes.goxcelObj = goxcelObj
shapes.comObj = comObj
return shapes
}
func NewShapesFromWorksheet(ws *Worksheet, comObj *ole.IDispatch) *Shapes {
return newShapes(ws, comObj)
}
func (ss *Shapes) Goxcel() *Goxcel {
return ss.goxcelObj.Goxcel()
}
func (ss *Shapes) Releaser() *Releaser {
return ss.Goxcel().Releaser()
}
func (ss *Shapes) ComObject() *ole.IDispatch {
return ss.comObj
}
func (ss *Shapes) Count() (int32, error) {
v, err := oleutil.GetProperty(ss.ComObject(), "Count")
if err != nil {
return 0, err
}
count, ok := v.Value().(int32)
if !ok {
return 0, ValueCantConvertToInt
}
return count, nil
}
func (ss *Shapes) Item(index int) (*Shape, error) {
v, err := oleutil.CallMethod(ss.ComObject(), "Item", index)
if err != nil {
return nil, err
}
shape := NewShape(ss, v.ToIDispatch())
return shape, nil
}
func (ss *Shapes) Walk(walkFn func(s *Shape, index int) error) (*Shape, error) {
count, err := ss.Count()
if err != nil {
return nil, err
}
for i := 1; i <= int(count); i++ {
s, err := ss.Item(i)
if err != nil {
return nil, err
}
err = walkFn(s, i)
if err != nil {
return s, err
}
}
return nil, nil
}
func (ss *Shapes) AddPicture(filename string, left, top, width, height int) error {
_, err := oleutil.CallMethod(ss.ComObject(), "AddPicture", filename, false, true, left, top, width, height)
if err != nil {
return err
}
return nil
}