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

Delete sheet breaks AutoFilter #775

Closed
pandaadb opened this issue Feb 1, 2021 · 4 comments
Closed

Delete sheet breaks AutoFilter #775

pandaadb opened this issue Feb 1, 2021 · 4 comments
Projects

Comments

@pandaadb
Copy link

pandaadb commented Feb 1, 2021

Description

When using autoFilter, removing Sheet1 seems to be breaking the entire file.

This is tested with LibreOffice on ubuntu.

When uploaded to Office365, it says the file has been repaired.

Steps to reproduce the issue:

Code:

        f := excelize.NewFile()

	f.NewSheet("sheet_test")
	for i := 0; i < 5; i++ {
		idx, _ := excelize.CoordinatesToCellName(i+1, 1)
		f.SetCellValue("sheet_test", idx, fmt.Sprintf("Header %d", i))
	}

	row := 2

	for j := 0; j < 10; j++ {

		for i := 0; i < 5; i++ {
			idx, _ := excelize.CoordinatesToCellName(i+1, row)
			f.SetCellValue("sheet_test", idx, fmt.Sprintf("Value %d", i))
		}

		row++
	}

	f.AutoFilter("sheet_test", "A1", "E11", "")

	f.DeleteSheet("Sheet1")
	f.SetActiveSheet(0)

	filename := "/tmp/test4.xlsx"

	f.SaveAs(filename)

Describe the results you received:

When opening the file, Libre office reports:

General input/output error

Describe the results you expected:

A 1 sheet xlsx file, containing the Autofilter.

Output of go version:

go version go1.13.10 linux/amd64

Excelize version or commit ID:

github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.2

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

Ubuntu 18.04
LibreOffice (LibreOffice 6.0.7.3 00m0(Build:3)

@xuri
Copy link
Member

xuri commented Feb 1, 2021

Thanks for your issue. As the docs of the DeleteSheet noticed, this issue caused by some references not removed after deleting the worksheet which has the auto filter, I'll consider resolving it.

@pandaadb
Copy link
Author

pandaadb commented Feb 1, 2021

Oh that makes sense. I am sorry, I hadn't read the docs on DeleteSheet!

A question, is there a "safe" way to create a new spreadsheet without the first Sheet? I resolved to removing it because I had no idea how to get rid off it :)

@xuri
Copy link
Member

xuri commented Feb 1, 2021

If you needn't the default worksheet named Sheet1, you can rename it by SetSheetName("Sheet1", "sheet_test") before coming up with operations.

@xuri xuri added the in progress Working in progress label Feb 2, 2021
@xuri xuri added this to In progress in v2.4.0 Feb 2, 2021
@xuri xuri closed this as completed in 1f329e8 Feb 2, 2021
v2.4.0 automation moved this from In progress to Bugfix Feb 2, 2021
@xuri
Copy link
Member

xuri commented Feb 2, 2021

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 Feb 2, 2021
jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this issue Oct 22, 2023
- correct adjust calculation chain in duplicate rows
- correct adjust defined name in the workbook when delete worksheet
- use absolute reference in the auto filters defined name to make it compatible with OpenOffice
- API `CoordinatesToCellName` have a new optional param to specify if using an absolute reference format
- Fix cyclomatic complexity issue of internal function `newFills` and `parseToken`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
v2.4.0
Bugfix
Development

No branches or pull requests

2 participants