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

SetActiveSheet Doesn't Work? #735

Closed
AngangGuo opened this issue Nov 20, 2020 · 2 comments
Closed

SetActiveSheet Doesn't Work? #735

AngangGuo opened this issue Nov 20, 2020 · 2 comments
Labels
confirmed This issue can be reproduced

Comments

@AngangGuo
Copy link

The following sample program will create a file named "test.xlsx". After I opened this file with Microsoft Excel Version 2008(Microsoft 365 Apps for enterprise), the "Details" sheet shows out instead of "Summary".

Is it an Excelize bug?

package main

import "github.com/360EntSecGroup-Skylar/excelize/v2"

func main()  {
	f := excelize.NewFile()
	summarySheet := "Summary"
	nSummary := f.NewSheet(summarySheet)
	detailSheet := "Details"
	f.NewSheet(detailSheet)

	// remove the default sheet
	defaultSheet:="Sheet1"
	f.DeleteSheet(defaultSheet)

	f.SetActiveSheet(nSummary)
	f.SaveAs("test.xlsx")
}
@AngangGuo
Copy link
Author

It is becaused the sheet index changed after I deleted the default sheet.
But even if I move the SetActiveSheet right after the sheet created, it still active the "Details" sheet.

func main()  {
	f := excelize.NewFile()
	summarySheet := "Summary"
	nSummary := f.NewSheet(summarySheet)
	// this doesn't work if I delete the default sheet after
	f.SetActiveSheet(nSummary)
	fmt.Println(f.GetSheetName(nSummary))
	
	detailSheet := "Details"
	f.NewSheet(detailSheet)

	// remove the default sheet
	defaultSheet:="Sheet1"
	f.DeleteSheet(defaultSheet)

	fmt.Println(f.GetSheetName(nSummary))
	f.SaveAs("test1.xlsx")
}

Out put

Summary
Details

@xuri xuri added confirmed This issue can be reproduced in progress Working in progress labels Nov 22, 2020
@xuri xuri closed this as completed in 13e0ed2 Nov 22, 2020
@xuri
Copy link
Member

xuri commented Nov 22, 2020

Thanks for your issue. I have fixed it, please try to use the master branch code, and this patch will be released in the next version.

@xuri xuri removed the in progress Working in progress label Nov 22, 2020
jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this issue Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed This issue can be reproduced
Projects
None yet
Development

No branches or pull requests

2 participants