excelize/cell.go

41 lines
955 B
Go
Raw Normal View History

package excelize
import (
"encoding/xml"
"strconv"
"strings"
)
2016-09-02 11:54:52 +08:00
// GetCellValue provide function get value from cell by given sheet index and axis in XLSX file
func GetCellValue(file map[string]string, 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`
2016-09-02 11:54:52 +08:00
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)
2016-09-02 11:54:52 +08:00
xml.Unmarshal([]byte(readXML(file, `xl/sharedStrings.xml`)), &shardStrings)
return shardStrings.SI[xlsxSI].T
case "str":
return v.V
default:
return v.V
}
}
}
}
return ``
}