This project has moved and is read-only. For the latest updates, please go here.

Hide the Column dynamically

Feb 28, 2011 at 8:47 AM


 i want hide the column when the column contains no value.How to do that,please help me to solve this issue..

Example,    I set the Heading in 4th Row...

               Heading1    Heading2      Heading3

              1                   2                

              3                  4                      

                        Here,  Heading3 column contains no values,so that i want to hide the column3... How to do that please Help me.....



Gnanadesigan kannan



Feb 28, 2011 at 2:40 PM
Edited Feb 28, 2011 at 2:44 PM

You can use a linq querie in your target column or a simple "for-loop" using rows.dimension to check all cells. If exists any value, hide your column.

Please, look at sample folder, you´ll find a lot of linq queries. If you want to hidden a column you can do "worksheet.Column(pos).Hidden = true;"

Mar 12, 2012 at 9:05 AM

Hi mrxrsd,

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

using (ExcelPackage pck = new ExcelPackage())       


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

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

ws.Column(1).Hidden = true;


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

Thanks for your effort!