Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using EPPLUS DLL ver 5.4.0 and need to filter table by a column value (column D). Here is my C# code for creating excel file sheet:

DataTable dt = MappingDataset.loadQuery(dbQuery);
ExcelWorksheet sheet = excelPackage.Workbook.Worksheets.Add("SHEET 1");
sheet.Cells["A1"].LoadFromDataTable(dt, true);
string ct1 = ((dt.Rows.Count + 1) + "");
sheet.Cells["A1:F" ct1].AutoFilter = true;
sheet.Cells["A1:F" ct1].AutoFitColumns();



Column D will be populated with values ('YES','NO). How can I apply auto filter rows having D column value as 'NO' before saving the excel file.

I have tried hiding the rows with D column value as 'YES', but that is not what I am trying to achieve. I don't want to hide the rows, I need to filter the rows with column D value.

//sheet.Cells.Where(cell => cell.Address.StartsWith("D") && cell.Value.ToString().Equals("YES")).Select(cell => cell.Start.Row).ToList().ForEach(r => sheet.Row(r).Hidden = true);


Thanks for support in advance.

What I have tried:

<pre>DataTable dt = MappingDataset.loadQuery(dbQuery);
ExcelWorksheet sheet = excelPackage.Workbook.Worksheets.Add("SHEET 1");
sheet.Cells["A1"].LoadFromDataTable(dt, true);
string ct1 = ((dt.Rows.Count + 1) + "");
sheet.Cells["A1:F" ct1].AutoFilter = true;
sheet.Cells["A1:F" ct1].AutoFitColumns();


//sheet.Cells.Where(cell => cell.Address.StartsWith("D") && cell.Value.ToString().Equals("YES")).Select(cell => cell.Start.Row).ToList().ForEach(r => sheet.Row(r).Hidden = true);
Posted
Updated 19-Oct-20 2:32am

1 solution

if this is really an Excel question, consider asking it on an Excel forum: [^]

if you think this is an issue specific to EPPlus, you may want to raise an issue on EPPlus' new github site: [^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900