Skip to content

Commit

Permalink
Merge pull request #792 from neddy299/fix/autofilter-for-excel
Browse files Browse the repository at this point in the history
Fix Excel opening files with AutoFilter data
  • Loading branch information
tealeg committed Jan 3, 2024
2 parents cab4e03 + 5b2ba9d commit 1f3b461
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 1f3b461

Please sign in to comment.