EPPlus set table column filter with text contains

Viewed 174

I'm trying to achieve this with EPPlus -

enter image description here

I looked at the example here:

    private static async Task CustomFilter(string connectionString, ExcelPackage p)
    {
        var ws = p.Workbook.Worksheets.Add("CustomFilter");
        ExcelRangeBase range = await LoadFromDatabase(connectionString, ws);

        range.AutoFilter = true;
        var colCompany = ws.AutoFilter.Columns.AddCustomFilterColumn(6);
        colCompany.And = true;
        colCompany.Filters.Add(new ExcelFilterCustomItem("999.99",eFilterOperator.GreaterThan));
        colCompany.Filters.Add(new ExcelFilterCustomItem("1500", eFilterOperator.LessThanOrEqual));
        ws.AutoFilter.ApplyFilter();
        range.AutoFitColumns(0);
    }

It looks like eFilterOperator doesn't have a contains option, however. Is this possible?

1 Answers

Figured it out, needed to use asterisks. BTW - If the value begins with an asterisk the filter will show up as ends with instead of contains.

$xl = New-Object OfficeOpenXml.ExcelPackage $xls
$ws = $xl.Workbook.Worksheets.Add("Logs")
$table_range = $ws.Cells[1, 1, $ws.Dimension.End.Row, $ws.Dimension.End.Column]
$table = $ws.Tables.Add($table_range, 'Table1')
$filter = $table.AutoFilter.Columns.AddCustomFilterColumn($colinfo['File'].Index - 1)
$filter.Filters.Add( (New-Object 'OfficeOpenXml.Filter.ExcelFilterCustomItem' '*MAIN-Install.log*', 'Equal' ) )
$filter.Filters.Add( (New-Object 'OfficeOpenXml.Filter.ExcelFilterCustomItem' '*dsclog.log*', 'Equal' ) )
$table.AutoFilter.ApplyFilter()
Related