Hide columns

Mar 10, 2012 at 5:11 AM

Hi all,

I have a requirement where i need to hide some columns in my excel (.xlsx).

using (ExcelPackage pck = new ExcelPackage())       


ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");

ws.Cells["A1"].LoadFromDataTable(dtExcelData, true);           

ws.Column(1).Hidden = true;


Using the above code i tried to hide column 1 of my excel sheet. But no luck.

Can someone please suggest me how can i resolve this issue.

Thanks all for your effort!

Mar 14, 2012 at 8:29 AM

I have the same problem. It seems as it is not possible to hide colums in a table. If I try outside the table the Hide works.



Mar 15, 2012 at 12:31 AM

this works for me:

    ws.Column(ColDiscounted).Style.Hidden = true;

Mar 15, 2012 at 8:21 PM

Your sample works for me...

ws.Column(1).Hidden = true;

Make sure you don't use the column/range AutoFit methods or set the width of the column afterwards

You could also set the ws.Column(1).Width=0