From b4ffa8ce48fdddc9b269d254b25e93921b8327f2 Mon Sep 17 00:00:00 2001 From: Ri Xu Date: Wed, 18 Oct 2017 18:42:20 +0800 Subject: [PATCH] - Add unsigned integer data type support, related issue #136; - go test and godoc updated Signed-off-by: Ri Xu --- cell.go | 15 +++++++++++++++ excelize_test.go | 23 ++++++++++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/cell.go b/cell.go index 36b8ef9..c4edf71 100644 --- a/cell.go +++ b/cell.go @@ -30,6 +30,11 @@ func (f *File) mergeCellsParser(xlsx *xlsxWorksheet, axis string) string { // int16 // int32 // int64 +// uint +// uint8 +// uint16 +// uint32 +// uint64 // float32 // float64 // string @@ -51,6 +56,16 @@ func (f *File) SetCellValue(sheet, axis string, value interface{}) { f.SetCellInt(sheet, axis, int(value.(int32))) case int64: f.SetCellInt(sheet, axis, int(value.(int64))) + case uint: + f.SetCellInt(sheet, axis, int(value.(uint))) + case uint8: + f.SetCellInt(sheet, axis, int(value.(uint8))) + case uint16: + f.SetCellInt(sheet, axis, int(value.(uint16))) + case uint32: + f.SetCellInt(sheet, axis, int(value.(uint32))) + case uint64: + f.SetCellInt(sheet, axis, int(value.(uint64))) case float32: f.SetCellDefault(sheet, axis, strconv.FormatFloat(float64(value.(float32)), 'f', -1, 32)) case float64: diff --git a/excelize_test.go b/excelize_test.go index 5c14c52..7e88271 100644 --- a/excelize_test.go +++ b/excelize_test.go @@ -67,16 +67,21 @@ func TestOpenFile(t *testing.T) { xlsx.SetCellValue("Sheet2", "F1", " Hello") xlsx.SetCellValue("Sheet2", "G1", []byte("World")) xlsx.SetCellValue("Sheet2", "F2", 42) - xlsx.SetCellValue("Sheet2", "F2", int8(42)) - xlsx.SetCellValue("Sheet2", "F2", int16(42)) - xlsx.SetCellValue("Sheet2", "F2", int32(42)) - xlsx.SetCellValue("Sheet2", "F2", int64(42)) - xlsx.SetCellValue("Sheet2", "F2", float32(42.65418)) - xlsx.SetCellValue("Sheet2", "F2", float64(-42.65418)) - xlsx.SetCellValue("Sheet2", "F2", float32(42)) - xlsx.SetCellValue("Sheet2", "F2", float64(42)) + xlsx.SetCellValue("Sheet2", "F3", int8(1<<8/2-1)) + xlsx.SetCellValue("Sheet2", "F4", int16(1<<16/2-1)) + xlsx.SetCellValue("Sheet2", "F5", int32(1<<32/2-1)) + xlsx.SetCellValue("Sheet2", "F6", int64(1<<32/2-1)) + xlsx.SetCellValue("Sheet2", "F7", float32(42.65418)) + xlsx.SetCellValue("Sheet2", "F8", float64(-42.65418)) + xlsx.SetCellValue("Sheet2", "F9", float32(42)) + xlsx.SetCellValue("Sheet2", "F10", float64(42)) + xlsx.SetCellValue("Sheet2", "F11", uint(1<<32-1)) + xlsx.SetCellValue("Sheet2", "F12", uint8(1<<8-1)) + xlsx.SetCellValue("Sheet2", "F13", uint16(1<<16-1)) + xlsx.SetCellValue("Sheet2", "F14", uint32(1<<32-1)) + xlsx.SetCellValue("Sheet2", "F15", uint64(1<<32-1)) + xlsx.SetCellValue("Sheet2", "F16", true) xlsx.SetCellValue("Sheet2", "G2", nil) - xlsx.SetCellValue("Sheet2", "G3", uint8(8)) xlsx.SetCellValue("Sheet2", "G4", time.Now()) // Test completion column. xlsx.SetCellValue("Sheet2", "M2", nil)