diff --git a/cell.go b/cell.go index bbbb83a..fe393ec 100644 --- a/cell.go +++ b/cell.go @@ -1319,7 +1319,7 @@ func (f *File) formattedValue(s int, v string, raw bool) (string, error) { if styleSheet.CellXfs == nil { return v, err } - if s >= len(styleSheet.CellXfs.Xf) { + if s >= len(styleSheet.CellXfs.Xf) || s < 0 { return v, err } var numFmtID int diff --git a/cell_test.go b/cell_test.go index 69a3f81..2a9357a 100644 --- a/cell_test.go +++ b/cell_test.go @@ -2,6 +2,7 @@ package excelize import ( "fmt" + _ "image/jpeg" "os" "path/filepath" "reflect" @@ -11,8 +12,6 @@ import ( "testing" "time" - _ "image/jpeg" - "github.com/stretchr/testify/assert" ) @@ -755,10 +754,16 @@ func TestFormattedValue(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "43528", result) + // S is too large result, err = f.formattedValue(15, "43528", false) assert.NoError(t, err) assert.Equal(t, "43528", result) + // S is too small + result, err = f.formattedValue(-15, "43528", false) + assert.NoError(t, err) + assert.Equal(t, "43528", result) + result, err = f.formattedValue(1, "43528", false) assert.NoError(t, err) assert.Equal(t, "43528", result)