Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable autofilter in closedXml c#?

I am facing a weird problem in closedXML library.

I am exporting a datatable to .xlsx (excel file) using closedXML library. By default, autofilter is enabled in the library.

I want to disable or remove the autofilter and export only the datatable.

Here is the code I tried but its not working

XLWorkbook wb = new XLWorkbook();
var ws = wb.Worksheets.Add("Test");
ws.Cell(1, 1).InsertTable(dataTable);
ws.AutoFilter.Enabled = false;
ws.Columns().AdjustToContents();
wb.SaveAs("Report.xlsx");

and I also tried

ws.AutoFilter.Clear();

Even the column wise clear filter is not working

ws.AutoFilter.Column(1).Clear();
like image 811
CST RAIZE Avatar asked Dec 22 '15 09:12

CST RAIZE


1 Answers

Try to use below code and it should work fine

ws.Tables.FirstOrDefault().ShowAutoFilter = false;
like image 185
Hamaresha Avatar answered Sep 30 '22 02:09

Hamaresha