Skip to content

Commit d65b300

Browse files
committed
- Update the function NewSheet() to handle when already exists a worksheet of the same name, relate pull request qax-os#196;
- go test and godoc has been updated
1 parent 770026e commit d65b300

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Diff for: excelize_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ func TestBrokenFile(t *testing.T) {
190190
func TestNewFile(t *testing.T) {
191191
// Test create a XLSX file.
192192
xlsx := NewFile()
193+
xlsx.NewSheet("Sheet1")
193194
xlsx.NewSheet("XLSXSheet2")
194195
xlsx.NewSheet("XLSXSheet3")
195196
xlsx.SetCellInt("XLSXSheet2", "A23", 56)

Diff for: sheet.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ import (
1313
)
1414

1515
// NewSheet provides function to create a new sheet by given index, when
16-
// creating a new XLSX file, the default sheet will be create, when you create a
17-
// new file.
16+
// creating a new XLSX file, the default sheet will be create, when you create
17+
// a new file.
1818
func (f *File) NewSheet(name string) int {
19+
// Check if the worksheet already exists
20+
if f.GetSheetIndex(name) != 0 {
21+
return f.SheetCount
22+
}
1923
f.SheetCount++
2024
// Update docProps/app.xml
2125
f.setAppXML()

0 commit comments

Comments
 (0)