2016-08-30 21:54:28 +08:00
|
|
|
package excelize
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2016-10-19 20:39:44 +08:00
|
|
|
// GetCellValue provide function get value from cell by given sheet index and axis in XLSX file.
|
2016-09-05 16:37:15 +08:00
|
|
|
func (f *File) GetCellValue(sheet string, axis string) string {
|
2016-08-30 21:54:28 +08:00
|
|
|
axis = strings.ToUpper(axis)
|
|
|
|
var xlsx xlsxWorksheet
|
2016-09-12 17:37:06 +08:00
|
|
|
row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis))
|
2016-08-30 21:54:28 +08:00
|
|
|
xAxis := row - 1
|
|
|
|
name := `xl/worksheets/` + strings.ToLower(sheet) + `.xml`
|
2016-09-05 16:37:15 +08:00
|
|
|
xml.Unmarshal([]byte(f.readXML(name)), &xlsx)
|
2016-08-30 21:54:28 +08:00
|
|
|
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-05 16:37:15 +08:00
|
|
|
xml.Unmarshal([]byte(f.readXML(`xl/sharedStrings.xml`)), &shardStrings)
|
2016-08-30 21:54:28 +08:00
|
|
|
return shardStrings.SI[xlsxSI].T
|
|
|
|
case "str":
|
|
|
|
return v.V
|
|
|
|
default:
|
|
|
|
return v.V
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ``
|
|
|
|
}
|