Clear filters in Excel where MS office is not installed in server using macros or .net


  • Our requirement is to clear existing filters and apply new filters in Excel where MS office is not installed in server. Later on excel data of newly applied filters to be loaded into SQL using SSIS.

    Could you please suggest? Thanks in advance.

    Tuesday, January 2, 2018 9:43 AM

All replies

  • If the files in question are .xlsx then look at SpreadSheetLight (free) library that does not require Excel to be installed.

    Example targeting a WorkSheet in a specific Excel file (you would specify the full path to the file.

    Using doc As New SLDocument("SomeFileName.xlsx", "SheetName")
    End Using

    SpreadsheetLight is installed via NuGet, also requires from NuGet DocumentFormat.OpenXml which you need to install with version 2.5 (see my code sample, section "Building the sample").

    There is ClosedXml library on GitHub (all examples are in C# so you will need to transpose to VB.NET), below "ws" is a WorkSheet object from the library.

    ws.Tables.FirstOrDefault().ShowAutoFilter = False

    Your other options are to use a paid library such as GemBox Spreadsheet library

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, January 2, 2018 10:39 AM