@@ -20,6 +20,19 @@ import (
20
20
"time"
21
21
)
22
22
23
+ // CellType is the type of cell value type.
24
+ type CellType byte
25
+
26
+ // Cell value types enumeration.
27
+ const (
28
+ CellTypeUnset CellType = iota
29
+ CellTypeBool
30
+ CellTypeDate
31
+ CellTypeError
32
+ CellTypeNumber
33
+ CellTypeString
34
+ )
35
+
23
36
const (
24
37
// STCellFormulaTypeArray defined the formula is an array formula.
25
38
STCellFormulaTypeArray = "array"
@@ -31,6 +44,17 @@ const (
31
44
STCellFormulaTypeShared = "shared"
32
45
)
33
46
47
+ // cellTypes mapping the cell's data type and enumeration.
48
+ var cellTypes = map [string ]CellType {
49
+ "b" : CellTypeBool ,
50
+ "d" : CellTypeDate ,
51
+ "n" : CellTypeNumber ,
52
+ "e" : CellTypeError ,
53
+ "s" : CellTypeString ,
54
+ "str" : CellTypeString ,
55
+ "inlineStr" : CellTypeString ,
56
+ }
57
+
34
58
// GetCellValue provides a function to get formatted value from cell by given
35
59
// worksheet name and axis in spreadsheet file. If it is possible to apply a
36
60
// format to the cell value, it will do so, if not then an error will be
@@ -43,6 +67,32 @@ func (f *File) GetCellValue(sheet, axis string, opts ...Options) (string, error)
43
67
})
44
68
}
45
69
70
+ // GetCellType provides a function to get the cell's data type by given
71
+ // worksheet name and axis in spreadsheet file.
72
+ func (f * File ) GetCellType (sheet , axis string ) (CellType , error ) {
73
+ cellTypes := map [string ]CellType {
74
+ "b" : CellTypeBool ,
75
+ "d" : CellTypeDate ,
76
+ "n" : CellTypeNumber ,
77
+ "e" : CellTypeError ,
78
+ "s" : CellTypeString ,
79
+ "str" : CellTypeString ,
80
+ "inlineStr" : CellTypeString ,
81
+ }
82
+ var (
83
+ err error
84
+ cellTypeStr string
85
+ cellType CellType = CellTypeUnset
86
+ )
87
+ if cellTypeStr , err = f .getCellStringFunc (sheet , axis , func (x * xlsxWorksheet , c * xlsxC ) (string , bool , error ) {
88
+ return c .T , true , nil
89
+ }); err != nil {
90
+ return CellTypeUnset , err
91
+ }
92
+ cellType = cellTypes [cellTypeStr ]
93
+ return cellType , err
94
+ }
95
+
46
96
// SetCellValue provides a function to set the value of a cell. The specified
47
97
// coordinates should not be in the first row of the table, a complex number
48
98
// can be set with string text. The following shows the supported data
0 commit comments