提交 2a3620e7 编写于 作者: xurime's avatar xurime

BugFix: `SetCellValue` function assertion logic will cause panic in some case.

上级 6adcb9d8
......@@ -37,8 +37,20 @@ func OpenFile(filename string) (*File, error) {
// SetCellValue provide function to set int or string type value of a cell.
func (f *File) SetCellValue(sheet string, axis string, value interface{}) {
switch t := value.(type) {
case int, int8, int16, int32, int64, float32, float64:
case int:
f.SetCellInt(sheet, axis, value.(int))
case int8:
f.SetCellInt(sheet, axis, int(value.(int8)))
case int16:
f.SetCellInt(sheet, axis, int(value.(int16)))
case int32:
f.SetCellInt(sheet, axis, int(value.(int32)))
case int64:
f.SetCellInt(sheet, axis, int(value.(int64)))
case float32:
f.SetCellInt(sheet, axis, int(value.(float32)))
case float64:
f.SetCellInt(sheet, axis, int(value.(float64)))
case string:
f.SetCellStr(sheet, axis, t)
case []byte:
......
......@@ -40,6 +40,12 @@ func TestExcelize(t *testing.T) {
f1.SetCellValue("Sheet2", "F1", "Hello")
f1.SetCellValue("Sheet2", "G1", []byte("World"))
f1.SetCellValue("Sheet2", "F2", 42)
f1.SetCellValue("Sheet2", "F2", int8(42))
f1.SetCellValue("Sheet2", "F2", int16(42))
f1.SetCellValue("Sheet2", "F2", int32(42))
f1.SetCellValue("Sheet2", "F2", int64(42))
f1.SetCellValue("Sheet2", "F2", float32(42))
f1.SetCellValue("Sheet2", "F2", float64(42))
f1.SetCellValue("Sheet2", "G2", nil)
// Test completion column.
f1.SetCellValue("Sheet2", "M2", nil)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册