diff options
author | Ri Xu <xuri.me@gmail.com> | 2017-05-05 14:40:28 +0800 |
---|---|---|
committer | Ri Xu <xuri.me@gmail.com> | 2017-05-05 14:40:28 +0800 |
commit | 8fbab474443393b8b996487cf7ade300a72d2e07 (patch) | |
tree | bd863a7e6066ce62ecc01db110e508145057d3c9 /excelize.go | |
parent | 7f30a6c9430476bcd5fc1662523ada0e95f60947 (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 'excelize.go')
-rw-r--r-- | excelize.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/excelize.go b/excelize.go index 39adb87..18d08e2 100644 --- a/excelize.go +++ b/excelize.go @@ -4,11 +4,13 @@ import ( "archive/zip" "bytes" "encoding/xml" + "fmt" "io" "io/ioutil" "os" "strconv" "strings" + "time" ) // File define a populated XLSX file struct. @@ -84,8 +86,13 @@ func (f *File) SetCellValue(sheet, axis string, value interface{}) { f.SetCellStr(sheet, axis, t) case []byte: f.SetCellStr(sheet, axis, string(t)) - default: + case time.Time: + f.SetCellDefault(sheet, axis, strconv.FormatFloat(float64(timeToExcelTime(timeToUTCTime(value.(time.Time)))), 'f', -1, 32)) + f.SetCellStyle(sheet, axis, axis, `{"number_format": 22}`) + case nil: f.SetCellStr(sheet, axis, "") + default: + f.SetCellStr(sheet, axis, fmt.Sprintf("%v", value)) } } |