Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetSheetName function will remove the sheet when oldSheetName is same with newSheetName #713

Closed
hybnew opened this issue Oct 17, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@hybnew
Copy link

hybnew commented Oct 17, 2020

Description

SetSheetName will delete the sheet if old name is equals to new name

the source code of excelize v2.3.1 is below:

func (f *File) SetSheetName(oldName, newName string) {
	oldName = trimSheetName(oldName)
	newName = trimSheetName(newName)
	content := f.workbookReader()
	for k, v := range content.Sheets.Sheet {
		if v.Name == oldName {
			content.Sheets.Sheet[k].Name = newName
			f.sheetMap[newName] = f.sheetMap[oldName]
			delete(f.sheetMap, oldName) // we may add a check if newName == oldName before
		}
	}
}

Steps to reproduce the issue:

  1. get a excelize file f from Open f, err := excelize.OpenFile(g.Opts.TmplConf.TemplateLocation)
  2. f.SetSheetName(oldSheetName, name)
  3. f.SetCellStr(name)

Describe the results you received:
step 3 got sheet not exist
Describe the results you expected:
step 3 setCellStr err is nil.
Output of go version:

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/yubohe 1/Library/Caches/go-build"
GOENV="/Users/yubohe 1/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/yubohe 1/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/local/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/y4/z855mpsx2bqb5n091wrg0zh00000gq/T/go-build327334959=/tmp/go-build -gno-record-gcc-switches -fno-common"

Excelize version or commit ID:

v2.3.1

Environment details (OS, Microsoft Excel™ version, physical, etc.):

@xuri xuri added confirmed This issue can be reproduced bug Something isn't working labels Oct 17, 2020
xuri added a commit that referenced this issue Oct 17, 2020
@xuri
Copy link
Member

xuri commented Oct 17, 2020

Thanks for your issue, I have fixed it, please try to use the master branch code.

@xuri xuri closed this as completed Oct 17, 2020
@hybnew
Copy link
Author

hybnew commented Oct 21, 2020

@xuri Noted, thx , I'll upgrade when v2.3.2 release.

EugeneAndrosovPaser pushed a commit to ceearrashee/excelize that referenced this issue Nov 14, 2020
@xuri xuri removed the confirmed This issue can be reproduced label Nov 22, 2022
jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this issue Oct 22, 2023
…g worksheet when rename with same names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants