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

SetSheetVisible for datagrip export excel, will panic: runtime error: invalid memory address or nil pointer dereference #1969

Closed
quxionglie opened this issue Jul 30, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@quxionglie
Copy link

quxionglie commented Jul 30, 2024

Description

I use JetBrains datagrip database tool to export excel file, but using f.SetSheetVisible(sheet, false) will cause exception. But if I save it in excel and call f.SetSheetVisible(sheet, false) again, it will be normal.

step:
1.use datagrip,Right click on the SQL statement "execute to file " ,save as excel
2.call HideSheet(xxx)

input data : in.xlsx
in.xlsx

code:


func HideSheet(filename string) {
	slog.Info("处理文件", "filename", filename)
	f, err := excelize.OpenFile(filename)
	procError(err)

	defer func() {
		if err := f.Close(); err != nil {
			procError(err)
		}
	}()

	sheetList := f.GetSheetList()
	slog.Info("存在sheet列表", "sheetList", sheetList)
	if len(sheetList) == 2 {
		//隐藏第二个sheet
		sheet := sheetList[1]
		slog.Info("隐藏sheet", "sheet", sheet)
		err = f.SetSheetVisible(sheet, false)
		procError(err)

		err = f.SaveAs(filename)
		procError(err)
	}
}

func procError(err error) {
	if err != nil {
		slog.Info("错误", "err", err)
		os.Exit(-1)
	}
}

Output of go version:
go version go1.22.5 darwin/amd64

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x6fd04c0]

goroutine 1 [running]:
github.com/xuri/excelize/v2.(*File).SetSheetVisible(0xc000084540, {0xc00027c548, 0x5}, 0x0, {0x0, 0x0, 0xc000027ea8?})
        /Users/lie/go/pkg/mod/github.com/xuri/excelize/v2@v2.8.1/sheet.go:776 +0x3c0
main.HideSheet({0x702b1c0, 0x7})
        /Users/lie/goProjects/sql2excel/cmd/sheet/sheet_ctl.go:50 +0x287
main.main()
        /Users/lie/goProjects/sql2excel/cmd/sheet/sheet_ctl.go:15 +0x1f


image

Excelize version or commit ID:

github.com/xuri/excelize/v2 v2.8.1

Environment details (OS, Microsoft Excel™ version, physical, etc.):
Microsoft® Excel for Mac 版本 16.87 (24071426)

@xuri xuri added the bug Something isn't working label Jul 30, 2024
@xuri xuri moved this to Bugfix in Excelize v2.9.0 Jul 30, 2024
@xuri xuri added the in progress Working in progress label Jul 30, 2024
@xuri xuri closed this as completed in d21b598 Jul 31, 2024
@xuri
Copy link
Member

xuri commented Jul 31, 2024

Thanks for your issue. This issue has been fixed, please upgrade to the master branch code by go get -u github.com/xuri/excelize/v2@master, and this patch will be released in the next version.

@xuri xuri removed the in progress Working in progress label Jul 31, 2024
zhangyimingdatiancai pushed a commit to zhangyimingdatiancai/excelize that referenced this issue Aug 6, 2024
- Fix missing conditional formatting after remove column
- Fix the SetSheetVisible function panic on none views sheet
- Updated unit tests
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
No open projects
Status: Bugfix
Development

No branches or pull requests

2 participants