forked from qax-os/excelize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcell.go
40 lines (38 loc) · 918 Bytes
/
cell.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
package excelize
import (
"encoding/xml"
"strconv"
"strings"
)
// Get value from cell by given sheet index and axis in XLSX file
func GetCellValue(file []FileList, sheet string, axis string) string {
axis = strings.ToUpper(axis)
var xlsx xlsxWorksheet
row := getRowIndex(axis)
xAxis := row - 1
name := `xl/worksheets/` + strings.ToLower(sheet) + `.xml`
xml.Unmarshal([]byte(readXml(file, name)), &xlsx)
rows := len(xlsx.SheetData.Row)
if rows <= xAxis {
return ``
}
for _, v := range xlsx.SheetData.Row[xAxis].C {
if xlsx.SheetData.Row[xAxis].R == row {
if axis == v.R {
switch v.T {
case "s":
shardStrings := xlsxSST{}
xlsxSI := 0
xlsxSI, _ = strconv.Atoi(v.V)
xml.Unmarshal([]byte(readXml(file, `xl/sharedStrings.xml`)), &shardStrings)
return shardStrings.SI[xlsxSI].T
case "str":
return v.V
default:
return v.V
}
}
}
}
return ``
}