Skip to content

Commit

Permalink
Fix Excel opening files with AutoFilter data
Browse files Browse the repository at this point in the history
  • Loading branch information
neddy299 committed Jan 3, 2024
1 parent cab4e03 commit 5b2ba9d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion xmlWorksheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ func emitStructAsXML(v reflect.Value, name, xmlNS string) (xmlwriter.Elem, error
Name: "xmlns",
Value: xmlNS,
})
case "SheetData", "MergeCells", "DataValidations":
case "SheetData", "MergeCells", "DataValidations", "AutoFilter":
// Skip SheetData here, we explicitly generate this in writeXML below
// Microsoft Excel considers a mergeCells element before a sheetData element to be
// an error and will fail to open the document, so we'll be back with this data
Expand Down Expand Up @@ -773,6 +773,15 @@ func (worksheet *xlsxWorksheet) WriteXML(xw *xmlwriter.Writer, s *Sheet, styles
return err
}
}
if worksheet.AutoFilter != nil {
autoFilter, err := emitStructAsXML(reflect.ValueOf(worksheet.AutoFilter), "autoFilter", "")
if err != nil {
return err
}
if err := xw.Write(autoFilter); err != nil {
return err
}
}
return nil
}(),
xw.EndElem(output.Name),
Expand Down

0 comments on commit 5b2ba9d

Please sign in to comment.