Skip to content

Commit

Permalink
fix PR issues
Browse files Browse the repository at this point in the history
  • Loading branch information
artiz committed Dec 11, 2020
1 parent 4723c60 commit a96ed3e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
~$*.xlsx
test/Test*.xlsx
test/Test*.xlsm
# generated files
test/BadEncrypt.xlsx
test/BadWorkbook.SaveAsEmptyStruct.xlsx
test/*.png
*.out
*.test
Expand Down
6 changes: 3 additions & 3 deletions cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,11 +766,11 @@ func (f *File) formattedValue(s int, v string) string {
if s >= len(styleSheet.CellXfs.Xf) {
return v
}
if styleSheet.CellXfs.Xf[s].NumFmtID == nil {
return v
var numFmtID int
if styleSheet.CellXfs.Xf[s].NumFmtID != nil {
numFmtID = *styleSheet.CellXfs.Xf[s].NumFmtID
}

numFmtID := *styleSheet.CellXfs.Xf[s].NumFmtID
ok := builtInNumFmtFunc[numFmtID]
if ok != nil {
return ok(v, builtInNumFmt[numFmtID])
Expand Down
32 changes: 8 additions & 24 deletions cell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func TestSetCellRichText(t *testing.T) {
assert.EqualError(t, f.SetCellRichText("Sheet1", "A", richTextRun), `cannot convert cell "A" to coordinates: invalid cell name "A"`)
}

func TestFormattedValue(t *testing.T) {
func TestFormattedValue2(t *testing.T) {
f := NewFile()
v := f.formattedValue(0, "43528")
assert.Equal(t, "43528", v)
Expand All @@ -320,7 +320,6 @@ func TestFormattedValue(t *testing.T) {
assert.Equal(t, "03/04/2019", v)

// formatted value with no built-in number format ID
assert.NoError(t, err)
numFmtID := 5
f.Styles.CellXfs.Xf = append(f.Styles.CellXfs.Xf, xlsxXf{
NumFmtID: &numFmtID,
Expand All @@ -329,31 +328,16 @@ func TestFormattedValue(t *testing.T) {
assert.Equal(t, "43528", v)

// formatted value with invalid number format ID
assert.NoError(t, err)
f.Styles.CellXfs.Xf = append(f.Styles.CellXfs.Xf, xlsxXf{
NumFmtID: nil,
})
v = f.formattedValue(3, "43528")
assert.Equal(t, "43528", v)
}
func TestInvalidNumberFormatsLoad(t *testing.T) {
f, err := OpenFile(filepath.Join("test", "Items.xlsx"))
assert.NoError(t, err)

rows, err := f.Rows("Sheet 1")
assert.NoError(t, err)

var rowCount int
for rows.Next() {
rowCount++
row, err := rows.Columns()
assert.NoError(t, err)

if rowCount > 1 {
assert.Equal(t, "0.5", row[13])
assert.Equal(t, "12/08/2020", row[14])
}
}

assert.Equal(t, 20, rowCount)
// formatted value with empty number format
f.Styles.NumFmts = nil
f.Styles.CellXfs.Xf = append(f.Styles.CellXfs.Xf, xlsxXf{
NumFmtID: &numFmtID,
})
v = f.formattedValue(1, "43528")
assert.Equal(t, "43528", v)
}
2 changes: 1 addition & 1 deletion crypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func TestEncrypt(t *testing.T) {
f, err := OpenFile(filepath.Join("test", "encryptSHA1.xlsx"), Options{Password: "password"})
assert.NoError(t, err)
assert.EqualError(t, f.SaveAs(filepath.Join("test", "TestBadEncrypt.xlsx"), Options{Password: "password"}), "not support encryption currently")
assert.EqualError(t, f.SaveAs(filepath.Join("test", "BadEncrypt.xlsx"), Options{Password: "password"}), "not support encryption currently")
}

func TestEncryptionMechanism(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion excelize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func TestBrokenFile(t *testing.T) {

t.Run("SaveAsEmptyStruct", func(t *testing.T) {
// Test write file with broken file struct with given path.
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestBadWorkbook.SaveAsEmptyStruct.xlsx")))
assert.NoError(t, f.SaveAs(filepath.Join("test", "BadWorkbook.SaveAsEmptyStruct.xlsx")))
})

t.Run("OpenBadWorkbook", func(t *testing.T) {
Expand Down
Binary file removed test/Items.xlsx
Binary file not shown.

0 comments on commit a96ed3e

Please sign in to comment.