Search code examples
c#excelcom

How to hide an excel column?



I need to hide an excel column entirely. I used the below code but didn't work:

public void Hide (params string[] columns)
{
    foreach(var column in columns)
    {
        Range range = (Range) oSheet.Columns[column, Type.Missing];
        range.EntireColumn.Hidden = true;
    }
}

What am I missing?


Solution

  • The above snippet is working .. sorry guys! The issue was that, my fellow colleague used to auto-fit all columns, right before saving the file, which will override my settings above. Yes, a function called CloseFile() that does two jobs, formats and then saves .. many responsibilities, eh?