Skip to content

GetSheetName doesn't work on this excel #457

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

Closed
EP-Toushirou opened this issue Aug 6, 2019 · 6 comments · Fixed by #463
Closed

GetSheetName doesn't work on this excel #457

EP-Toushirou opened this issue Aug 6, 2019 · 6 comments · Fixed by #463

Comments

@EP-Toushirou
Copy link

EP-Toushirou commented Aug 6, 2019

Description

GetSheetName doesn't work on this excel (other excels are no problem)
GetSheetName.xlsx

func ReadExcelFile(){
	f, err := excelize.OpenFile("./GetSheetName.xlsx")
	if err != nil {
		Println(err)
		return
	}

	fmt.Println(f.GetSheetName(1))
}

Steps to reproduce the issue:
1.Open the excel and read it and you can find it can't get the result "Sheet1",it got a empty string

Output of go version:
1.12.7

Excelize version or commit ID:
2019.08.04 update github

Environment details (OS, Microsoft Excel™ version, physical, etc.):
win10 1903
office 2019(but i don't know who create this excel and his excel version, it's on our svn)

@mlh758
Copy link
Contributor

mlh758 commented Aug 6, 2019

This opens fine for me on MacOS. "./GetSheetName.xlsx" doesn't look like valid path syntax on Windows.

@EP-Toushirou
Copy link
Author

EP-Toushirou commented Aug 7, 2019

you can test it on windows, other excels are no problem, but i don't know why this excel cannot get the sheet name. @mlh758

@mlh758
Copy link
Contributor

mlh758 commented Aug 7, 2019

Okay yeah I can reproduce this. GetSheetName looks for a sheet with an ID that matches the index. This presumably assumes that the IDs on the sheets are in order. The only sheet in this excel document has an ID of 5.

@mlh758
Copy link
Contributor

mlh758 commented Aug 7, 2019

It looks like changing the sheet order changes the order sheets appear within the <sheets> tag within workbook.xml. @xuri I think GetSheetName can be simplified to just check the index of the sheet against the Sheets field in a workbook.

@mlh758
Copy link
Contributor

mlh758 commented Aug 7, 2019

Go ahead and pull down the code from this PR and let me know if that fixes your issue.

@EP-Toushirou
Copy link
Author

@mlh758 yes, it can slove the problem.thank you.

@xuri xuri closed this as completed in #463 Aug 9, 2019
nullfy pushed a commit to nullfy/excelize that referenced this issue Oct 23, 2020
SheetID only seems to indicate the file name for the sheet.
Check the sheets list based on index instead. Reordering sheets
in Excel changes the order they appear in that list.

Fixes qax-os#457
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants