summaryrefslogtreecommitdiff
path: root/cell.go
diff options
context:
space:
mode:
authorRi Xu <xuri.me@gmail.com>2017-05-05 14:40:28 +0800
committerRi Xu <xuri.me@gmail.com>2017-05-05 14:40:28 +0800
commit8fbab474443393b8b996487cf7ade300a72d2e07 (patch)
treebd863a7e6066ce62ecc01db110e508145057d3c9 /cell.go
parent7f30a6c9430476bcd5fc1662523ada0e95f60947 (diff)
- Formatted cell data support, fix issue #48;
- Function `SetCellValue()` support `time.Time` data type parameter, relate issue #49; - go doc and go test updated
Diffstat (limited to 'cell.go')
-rw-r--r--cell.go24
1 files changed, 19 insertions, 5 deletions
diff --git a/cell.go b/cell.go
index c40012a..59a9947 100644
--- a/cell.go
+++ b/cell.go
@@ -6,8 +6,10 @@ import (
"strings"
)
-// GetCellValue provides function to get value from cell by given sheet index
-// and axis in XLSX file.
+// GetCellValue provides function to get formatted value from cell by given
+// sheet index and axis in XLSX file. If it is possible to apply a format to the
+// cell value, it will do so, if not then an error will be returned, along with
+// the raw value of the cell.
func (f *File) GetCellValue(sheet, axis string) string {
xlsx := f.workSheetReader(sheet)
axis = strings.ToUpper(axis)
@@ -44,17 +46,29 @@ func (f *File) GetCellValue(sheet, axis string) string {
xlsxSI := 0
xlsxSI, _ = strconv.Atoi(r.V)
xml.Unmarshal([]byte(f.readXML("xl/sharedStrings.xml")), &shardStrings)
- return shardStrings.SI[xlsxSI].T
+ return f.formattedValue(r.S, shardStrings.SI[xlsxSI].T)
case "str":
- return r.V
+ return f.formattedValue(r.S, r.V)
default:
- return r.V
+ return f.formattedValue(r.S, r.V)
}
}
}
return ""
}
+// formattedValue provides function to returns a value after formatted. If it is
+// possible to apply a format to the cell value, it will do so, if not then an
+// error will be returned, along with the raw value of the cell.
+func (f *File) formattedValue(s int, v string) string {
+ if s == 0 {
+ return v
+ }
+ var styleSheet xlsxStyleSheet
+ xml.Unmarshal([]byte(f.readXML("xl/styles.xml")), &styleSheet)
+ return builtInNumFmtFunc[styleSheet.CellXfs.Xf[s].NumFmtID](styleSheet.CellXfs.Xf[s].NumFmtID, v)
+}
+
// GetCellFormula provides function to get formula from cell by given sheet
// index and axis in XLSX file.
func (f *File) GetCellFormula(sheet, axis string) string {