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

AutoFilter - Excel crash #424

Closed
mickesommar opened this issue Nov 22, 2018 · 9 comments
Closed

AutoFilter - Excel crash #424

mickesommar opened this issue Nov 22, 2018 · 9 comments

Comments

@mickesommar
Copy link

mickesommar commented Nov 22, 2018

Then adding AutoFilter, excel crashes then sorting. But if I use the filter version first, then sorting is working.
Have tried with Excel 2010, 2013, Windows 7, Windows 10, Windows Server 2012.
In LibreOffice, the autofilter will not a peer.
Compiled with Go 1.11.1

The below code will create the file: names.xlsx, with AutoFilter.
Open the file, try to sort in the "Name" column. Excel will crash.
But if you try to use the filter, for example, only show the name "bob", then select all and sort. It will work.

Do I use the package wrong?

`
package main

import (
"github.com/tealeg/xlsx"
)

func main() {
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
var err error

file = xlsx.NewFile()
sheet, err = file.AddSheet("Sheet1")
if err != nil {
	panic(err)
}

// Header
row = sheet.AddRow()
cell = row.AddCell()

// Name 1
cell.Value = "Name"
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = "Mike"

// Name 2
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = "Bob"

// Name 3
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = "Kent"

// Add autofilter.
sheet.AutoFilter = &xlsx.AutoFilter{
	TopLeftCell:     "A1",
	BottomRightCell: "A4",
}

// Save file.
err = file.Save("names.xlsx")
if err != nil {
	panic(err)
}

}
`

@github-actions
Copy link

Stale issue message

@korpa
Copy link

korpa commented Mar 4, 2021

Any news on this? I have the same issue.

@tealeg
Copy link
Owner

tealeg commented Mar 4, 2021

@korpa sorry, no, I haven't even begun to look into this.

@korpa
Copy link

korpa commented Mar 4, 2021

I quickly checked the sheet1.xml. The only difference I saw between AutoFilter added by Excel and via the lib is that the position of the AutoFilter Node is different:

AutoFilter added via Excel:
image

AutoFilter added via lib:
image

@korpa
Copy link

korpa commented Mar 4, 2021

Ok. It seems, that the location of autoFilter really matters which is odd for XML.
I unzip the lib-generated Excel-File and moved the autoFilter node for between cols and sheetData below sheetData, zipped the file again.

Now Excel opens without an error message and I can filter and sort via auto filters.

By the way. I'm using github.com/tealeg/xlsx/v3 v3.2.3 and go 1.16

@korpa
Copy link

korpa commented Mar 4, 2021

It's geeting even stranger.

  • If autoFilter is between cols and sheetData Excel doesn't open the file. It just says it will try to recover as much data as possible. But Excel doen't show any data afterwards.

  • If I move the node below sheetData and rezip the file, Excel can open it.

  • If it is open and I directly try to use the AutoFilter sort, Excel crashes.

  • If I first change the filter, the sorting works.

This is exactlty as @mickesommar described the issue.

@tealeg
Copy link
Owner

tealeg commented Mar 4, 2021

Ok. It seems, that the location of autoFilter really matters which is odd for XML.

Odd for XML indeed - but not odd for Excel. We see these kinds of errors all the time (almost all of the "corruption" problems are this kind of thing). My belief (I don't know) is that Microsoft defined the XML standard as a simple translation of their raw data structures to XML, and that they simply translate them back and try to load them. That would explain why this sort of stuff works fine for any application that follows the standard except Excel.

@Arthur-Sk
Copy link

Can confirm. Files generated by the lib with autoFilters enabled cannot be opened via Microsoft Excel. No problem with LibreOffice or WPS Spreadsheets though.

@github-actions
Copy link

Stale issue message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants