summaryrefslogtreecommitdiff
path: root/cell.go
diff options
context:
space:
mode:
authorRi Xu <xuri.me@gmail.com>2016-08-30 21:54:28 +0800
committerRi Xu <xuri.me@gmail.com>2016-08-30 21:54:28 +0800
commit3c4ad28db75108dfd974b994df26ec7f33a69be7 (patch)
tree9f3f03683574b4e756b8467556ab2004f266b159 /cell.go
parent0d60020f9678c80df75d180cc874a24d80b1db08 (diff)
- Get cell value support
- Optimisation code use fmt package - Update README - Remove useless function
Diffstat (limited to 'cell.go')
-rw-r--r--cell.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/cell.go b/cell.go
new file mode 100644
index 0000000..4ce9619
--- /dev/null
+++ b/cell.go
@@ -0,0 +1,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 ``
+}