forked from unidoc/unioffice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
border.go
96 lines (84 loc) · 2.43 KB
/
border.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
94
95
96
// Copyright 2017 FoxyUtils ehf. All rights reserved.
//
// Use of this software package and source code is governed by the terms of the
// UniDoc End User License Agreement (EULA) that is available at:
// https://unidoc.io/eula/
// A trial license code for evaluation can be obtained at https://unidoc.io.
package spreadsheet
import (
"github.com/unidoc/unioffice"
"github.com/unidoc/unioffice/color"
"github.com/unidoc/unioffice/schema/soo/sml"
)
// Border is a cell border configuraton.
type Border struct {
x *sml.CT_Border
borders *sml.CT_Borders
}
// X returns the inner wrapped XML type.
func (b Border) X() *sml.CT_Border {
return b.x
}
// InitializeDefaults initializes a border to its defaulte empty values.
func (b Border) InitializeDefaults() {
b.x.Left = sml.NewCT_BorderPr()
b.x.Bottom = sml.NewCT_BorderPr()
b.x.Right = sml.NewCT_BorderPr()
b.x.Top = sml.NewCT_BorderPr()
b.x.Diagonal = sml.NewCT_BorderPr()
}
// Index returns the index of the border for use with a cell style.
func (b Border) Index() uint32 {
for i, bx := range b.borders.Border {
if bx == b.x {
return uint32(i)
}
}
return 0
}
func (b Border) SetLeft(style sml.ST_BorderStyle, c color.Color) {
if b.x.Left == nil {
b.x.Left = sml.NewCT_BorderPr()
}
b.x.Left.Color = sml.NewCT_Color()
b.x.Left.Color.RgbAttr = c.AsRGBAString()
b.x.Left.StyleAttr = style
}
func (b Border) SetRight(style sml.ST_BorderStyle, c color.Color) {
if b.x.Right == nil {
b.x.Right = sml.NewCT_BorderPr()
}
b.x.Right.Color = sml.NewCT_Color()
b.x.Right.Color.RgbAttr = c.AsRGBAString()
b.x.Right.StyleAttr = style
}
func (b Border) SetTop(style sml.ST_BorderStyle, c color.Color) {
if b.x.Top == nil {
b.x.Top = sml.NewCT_BorderPr()
}
b.x.Top.Color = sml.NewCT_Color()
b.x.Top.Color.RgbAttr = c.AsRGBAString()
b.x.Top.StyleAttr = style
}
func (b Border) SetBottom(style sml.ST_BorderStyle, c color.Color) {
if b.x.Bottom == nil {
b.x.Bottom = sml.NewCT_BorderPr()
}
b.x.Bottom.Color = sml.NewCT_Color()
b.x.Bottom.Color.RgbAttr = c.AsRGBAString()
b.x.Bottom.StyleAttr = style
}
func (b Border) SetDiagonal(style sml.ST_BorderStyle, c color.Color, up, down bool) {
if b.x.Diagonal == nil {
b.x.Diagonal = sml.NewCT_BorderPr()
}
b.x.Diagonal.Color = sml.NewCT_Color()
b.x.Diagonal.Color.RgbAttr = c.AsRGBAString()
b.x.Diagonal.StyleAttr = style
if up {
b.x.DiagonalUpAttr = unioffice.Bool(true)
}
if down {
b.x.DiagonalDownAttr = unioffice.Bool(true)
}
}