1

The issue with Table.ShowFilter, using EPPLUS library.
Created new ExcelTable in the sheet, but can't apply Table.ShowFilter = false.
The filters are still in the table. TableStyle and StyleName work fine.

ExcelTable et = (ExcelTable)Table;
int firstRow = newRow;
int lastRow;
if (DataStructure.Data != null)
      lastRow = newRow + DataStructure.Data.Count();
else
      lastRow = newRow + 1;

int firstColumn = OriginalAddress.StartColumn;
int lastColumn = OriginalAddress.EndColumn;

ExcelRange rg = ws.Cells[firstRow, firstColumn, lastRow, lastColumn];

Guid guid = Guid.NewGuid();
string str_guid = guid.ToString();
string tableName = et.Name + "_" + str_guid;

ExcelTable tab = wsTarget.Tables.Add(rg, tableName);
//  tab.ShowHeader = et.ShowHeader;
//  tab.TableStyle = et.TableStyle;
//  tab.StyleName = et.StyleName;
tab.ShowFilter = false;

Right table is desired result.

Please, help to fix!

Sergey
  • 47
  • 5

2 Answers2

0

Is this you want to mean?

tab.ShowHeader = false;

This very little example works here :

        using (ExcelPackage xls = new ExcelPackage())
        {
            ExcelWorksheet ws2 = xls.Workbook.Worksheets.Add("f1");
            OfficeOpenXml.Table.ExcelTable tab = ws2.Tables.Add(new ExcelAddressBase("a1:e5"), "table");
            //tab.TableStyle = et.TableStyle;
            //tab.StyleName = et.StyleName;
            tab.ShowFilter = false;

            FileInfo f = new FileInfo(@"d:\temp\test.xlsx");
            xls.SaveAs(f);
        }
DanB
  • 2,022
  • 1
  • 12
  • 24
  • Hi! No, ShowHeader works well, but ShowFilter not. In case tab.ShowFilter = false; filter buttons are still in the table. – Sergey Nov 08 '18 at 07:48
  • I'm not sure of what you don't want. Can you post a screen shot of expected result? – DanB Nov 08 '18 at 14:04
  • Daniel, please, take a look to the link above. Thank you for your help! – Sergey Nov 08 '18 at 18:53
  • Which version of epplus are you using? I'm using 4.5.2.1 and it works like you are expecting for. If you can't, give us more details, on `tab.TableStyle = et.TableStyle; tab.StyleName = et.StyleName;` and maybe elsewhere in your code. – DanB Nov 08 '18 at 19:08
  • Daniel, is also 4.5.2.1. Code example updated, commented tab.TableStyle = et.TableStyle; tab.StyleName = et.StyleName; Checked one more time - still active filters. – Sergey Nov 08 '18 at 19:38
  • Which version of Excel are you using? – DanB Nov 08 '18 at 19:39
  • Excel for Mac ver.16.18(181014) – Sergey Nov 08 '18 at 19:49
  • Just to be sure, can you test your Excel file in another computer (with another Excel version, or a Windows version of Excel)? Or, is there any way you can upload your file in StackOverflow? – DanB Nov 08 '18 at 19:52
  • Daniel, thank you a lot! Will try tomorrow on Windows computer. I'm working on template engine, so, there are two files: template and target.xlsx. I generate the target from new, clear workbook, based on template and json datasource. Which one do you mean to upload? Generated target? – Sergey Nov 08 '18 at 20:05
  • The generated one. And, did you try if my little test work on your side? You should try on a little(empty) file to see if issue is still there or not. – DanB Nov 08 '18 at 21:30
  • Daniel, your code works well on my computer. Looks like the problem is after ws2.DeleteColumn(1, 1), which i'm using... – Sergey Nov 09 '18 at 15:40
0

Probably, the bug. Adding ws2.DeleteColumn(1, 1) to the code, add filters to the table, even with tab.ShowFilter = false.

Workaround: put tab.ShowFilter = false right before file saving.

 using (ExcelPackage xls = new ExcelPackage())
        {
            ExcelWorksheet ws2 = xls.Workbook.Worksheets.Add("f1");
            OfficeOpenXml.Table.ExcelTable tab = ws2.Tables.Add(new ExcelAddressBase("d3:g8"), "table");
            //tab.TableStyle = et.TableStyle;
            //tab.StyleName = et.StyleName;

            ws2.DeleteColumn(1, 1);

            tab.ShowFilter = false;

            FileInfo f = new FileInfo(@"test.xlsx");
            xls.SaveAs(f);
        }
Sergey
  • 47
  • 5