浏览代码

- Update the function `NewSheet()` to handle when already exists a worksheet of the same name, relate pull request #196;
- go test and godoc has been updated

Ri Xu 7 年之前
父节点
当前提交
d65b30055d
共有 2 个文件被更改,包括 7 次插入2 次删除
  1. 1 0
      excelize_test.go
  2. 6 2
      sheet.go

+ 1 - 0
excelize_test.go

@@ -190,6 +190,7 @@ func TestBrokenFile(t *testing.T) {
 func TestNewFile(t *testing.T) {
 	// Test create a XLSX file.
 	xlsx := NewFile()
+	xlsx.NewSheet("Sheet1")
 	xlsx.NewSheet("XLSXSheet2")
 	xlsx.NewSheet("XLSXSheet3")
 	xlsx.SetCellInt("XLSXSheet2", "A23", 56)

+ 6 - 2
sheet.go

@@ -13,9 +13,13 @@ import (
 )
 
 // NewSheet provides function to create a new sheet by given index, when
-// creating a new XLSX file, the default sheet will be create, when you create a
-// new file.
+// creating a new XLSX file, the default sheet will be create, when you create
+// a new file.
 func (f *File) NewSheet(name string) int {
+	// Check if the worksheet already exists
+	if f.GetSheetIndex(name) != 0 {
+		return f.SheetCount
+	}
 	f.SheetCount++
 	// Update docProps/app.xml
 	f.setAppXML()