This closes #1906, fix a v2.8.1 regression bug introduced by commit d9a0da7b48

- Fix incorrect cell value written if save multiple times
- Update unit tests
This commit is contained in:
xuri 2024-05-24 22:05:07 +08:00
parent 5f583549f4
commit 42ad4d6959
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
2 changed files with 25 additions and 1 deletions

View File

@ -208,6 +208,30 @@ func TestSaveFile(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.NoError(t, f.Save()) assert.NoError(t, f.Save())
assert.NoError(t, f.Close()) assert.NoError(t, f.Close())
t.Run("for_save_multiple_times", func(t *testing.T) {
{
f, err := OpenFile(filepath.Join("test", "TestSaveFile.xlsx"))
assert.NoError(t, err)
assert.NoError(t, f.SetCellValue("Sheet1", "A20", 20))
assert.NoError(t, f.Save())
assert.NoError(t, f.SetCellValue("Sheet1", "A21", 21))
assert.NoError(t, f.Save())
assert.NoError(t, f.Close())
}
{
f, err := OpenFile(filepath.Join("test", "TestSaveFile.xlsx"))
assert.NoError(t, err)
val, err := f.GetCellValue("Sheet1", "A20")
assert.NoError(t, err)
assert.Equal(t, "20", val)
val, err = f.GetCellValue("Sheet1", "A21")
assert.NoError(t, err)
assert.Equal(t, "21", val)
assert.NoError(t, f.Close())
}
})
} }
func TestSaveAsWrongPath(t *testing.T) { func TestSaveAsWrongPath(t *testing.T) {

View File

@ -167,7 +167,7 @@ func (f *File) workSheetWriter() {
_, ok := f.checked.Load(p.(string)) _, ok := f.checked.Load(p.(string))
if ok { if ok {
f.Sheet.Delete(p.(string)) f.Sheet.Delete(p.(string))
f.checked.Store(p.(string), false) f.checked.Delete(p.(string))
} }
buffer.Reset() buffer.Reset()
} }