forked from plandem/excelize
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_sheet.go
More file actions
87 lines (67 loc) · 1.96 KB
/
Copy pathapi_sheet.go
File metadata and controls
87 lines (67 loc) · 1.96 KB
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
package excelize
import (
"strings"
"strconv"
)
type Worksheet struct {
f *File
sheet *xlsxWorksheet
}
func (w *Worksheet)mergeCellsParser(axis string) string {
axis = strings.ToUpper(axis)
if w.sheet.MergeCells != nil {
for i := 0; i < len(w.sheet.MergeCells.Cells); i++ {
if checkCellInArea(axis, w.sheet.MergeCells.Cells[i].Ref) {
axis = strings.Split(w.sheet.MergeCells.Cells[i].Ref, ":")[0]
}
}
}
return axis
}
func (w *Worksheet)axisToIndex(axis string)(int, int) {
axis = w.mergeCellsParser(axis)
col := string(strings.Map(letterOnlyMapF, axis))
row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis))
xAxis := row - 1
yAxis := TitleToNumber(col)
return xAxis, yAxis
}
func (w *Worksheet)GetRange(fromAxis, toAxis string)(*Range) {
fromAxis = strings.ToUpper(fromAxis)
toAxis = strings.ToUpper(toAxis)
fromXAxis, fromYAxis := w.axisToIndex(fromAxis)
toXAxis, toYAxis := w.axisToIndex(toAxis)
if toXAxis < fromXAxis {
fromAxis, toAxis = toAxis, fromAxis
toXAxis, fromXAxis = fromXAxis, toXAxis
}
if toYAxis < fromYAxis {
fromAxis, toAxis = toAxis, fromAxis
toYAxis, fromYAxis = fromYAxis, toYAxis
}
completeRow(w.sheet, toYAxis + 1, toXAxis + 1)
completeCol(w.sheet, toYAxis + 1, toXAxis + 1)
// Correct the coordinate area, such correct C1:B3 to B1:C3.
fromAxis = ToAlphaString(fromXAxis) + strconv.Itoa(fromYAxis + 1)
toAxis = ToAlphaString(toXAxis) + strconv.Itoa(toYAxis + 1)
return &Range{
w,
fromAxis,
toAxis,
}
}
func (w *Worksheet)getRow(rowIndex int, cells int)(*Row) {
completeRow(w.sheet, rowIndex + 1, cells)
return &Row{w, w.sheet.SheetData.Row[rowIndex]}
}
func (w *Worksheet)GetRow(rowIndex int)(*Row) {
return w.getRow(rowIndex, 0)
}
func (w *Worksheet)GetCell(axis string)(*Cell) {
xAxis, yAxis := w.axisToIndex(axis)
r := w.getRow(xAxis, yAxis + 1)
completeCol(w.sheet, xAxis + 1, yAxis + 1)
c := w.sheet.SheetData.Row[xAxis].C[yAxis]
r.w.f.prepareCellStyle(r.w.sheet, yAxis, c.S)
return &Cell{r, c}
}