private void FinalizeSheet()
        {
            if (writer != null)
            {
                writer.WriteEndElement(); // end of SheetData

                writer.WriteElement(new AutoFilter {
                    Reference = $"A1:{OXLHelper.GetColumnLetter(ColumnCount - 1)}{RowCount}"
                });

                writer.WriteEndElement(); // end of Worksheet
            }
        }
Beispiel #2
0
        private void CreateAutoFilterDefinedName()
        {
            var workbook = document.WorkbookPart.Workbook;

            if (workbook.DefinedNames == null)
            {
                workbook.DefinedNames = new DefinedNames();
            }

            var lastColumnIndex  = rowsWriter.ColumnCount - 1;
            var lastColumnLetter = OXLHelper.GetColumnLetter(lastColumnIndex);
            var rowCount         = rowsWriter.RowCount;

            var definedName = new DefinedName($"'{sheetName}'!$A$1:${lastColumnLetter}${rowCount}")
            {
                Name         = "_xlnm._FilterDatabase",
                LocalSheetId = 0,
                Hidden       = true
            };

            workbook.DefinedNames.AppendChild(definedName);
        }