diff --git a/xmlWorksheet.go b/xmlWorksheet.go index 16ddb7df..4cc92b1a 100644 --- a/xmlWorksheet.go +++ b/xmlWorksheet.go @@ -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 @@ -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),