-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathshape.go
69 lines (53 loc) · 1.26 KB
/
shape.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
package goxcel
import (
"github.com/devlights/goxcel/constants"
"github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
)
type (
Shape struct {
goxcelObj GoxcelObject
comObj *ole.IDispatch
}
)
func newShape(goxcelObj GoxcelObject, comObj *ole.IDispatch) *Shape {
shape := new(Shape)
shape.goxcelObj = goxcelObj
shape.comObj = comObj
shape.Releaser().Add(func() error {
shape.ComObject().Release()
return nil
})
return shape
}
func NewShape(ss *Shapes, c *ole.IDispatch) *Shape {
return newShape(ss, c)
}
func (s *Shape) Goxcel() *Goxcel {
return s.goxcelObj.Goxcel()
}
func (s *Shape) Releaser() *Releaser {
return s.Goxcel().Releaser()
}
func (s *Shape) ComObject() *ole.IDispatch {
return s.comObj
}
func (s *Shape) TopLeftCell() (*XlRange, error) {
v, err := oleutil.GetProperty(s.ComObject(), "TopLeftCell")
if err != nil {
return nil, err
}
ra := NewRangeFromShape(s, v.ToIDispatch())
return ra, nil
}
func (s *Shape) Type() (constants.MsoShapeType, error) {
v, err := oleutil.GetProperty(s.ComObject(), "Type")
if err != nil {
return constants.MsoShapeType(0), err
}
shapeType, ok := v.Value().(int)
if !ok {
return constants.MsoShapeType(0), ValueCantConvertToInt
}
return constants.MsoShapeType(shapeType), nil
}