forked from plandem/xlsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cell_formula_type.go
66 lines (53 loc) · 1.46 KB
/
cell_formula_type.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
// Copyright (c) 2017 Andrey Gayvoronsky <plandem@gmail.com>
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package primitives
import (
"encoding/xml"
)
//CellFormulaType is a type to encode XSD ST_CellFormulaType
type CellFormulaType byte
//List of all possible values for CellFormulaType
const (
_ CellFormulaType = iota
CellFormulaTypeNormal
CellFormulaTypeArray
CellFormulaTypeDataTable
CellFormulaTypeShared
)
var (
toCellFormulaType map[string]CellFormulaType
fromCellFormulaType map[CellFormulaType]string
)
func init() {
fromCellFormulaType = map[CellFormulaType]string{
CellFormulaTypeNormal: "normal",
CellFormulaTypeArray: "array",
CellFormulaTypeDataTable: "dataTable",
CellFormulaTypeShared: "shared",
}
toCellFormulaType = make(map[string]CellFormulaType, len(fromCellFormulaType))
for k, v := range fromCellFormulaType {
toCellFormulaType[v] = k
}
}
func (e CellFormulaType) String() string {
return fromCellFormulaType[e]
}
//MarshalXMLAttr marshal CellFormulaType
func (e *CellFormulaType) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
attr := xml.Attr{Name: name}
if v, ok := fromCellFormulaType[*e]; ok {
attr.Value = v
} else {
attr = xml.Attr{}
}
return attr, nil
}
//UnmarshalXMLAttr unmarshal CellFormulaType
func (e *CellFormulaType) UnmarshalXMLAttr(attr xml.Attr) error {
if v, ok := toCellFormulaType[attr.Value]; ok {
*e = v
}
return nil
}