Reputation: 620
Is it possible to unhide all hidden columns of an excel worksheet?
this is my code to unhide all hidden rows. I don't want to additionally check how far the used range of columns goes and iterate through it.
foreach (string filePath in _allFiles)
{
try
{
_wb = _app.Workbooks.Open(filePath, ReadOnly: false);
foreach (Excel.Worksheet ws in _wb.Worksheets)
{
try
{
string abc = ws.Name;
ws.ShowAllData(); /* needs try catch 'cause if no filters are applied, it will throw an exception */
}
catch (Exception ex)
{ }
}
}
catch (Exception ex2)
{ }
finally
{
_wb.Save();
_wb.Close();
//_app.Quit();
//Marshal.ReleaseComObject(_app);
}
}
_app.Quit();
Marshal.ReleaseComObject(_app);
Upvotes: 1
Views: 1232
Reputation: 31616
I found that to determine how to a specific action should be done, is to create a vba macro of the process. Then translate the macro into interop calls.
What I have found is that for each workbook, one can call and set (as shown in VBA macro) the columns and rows collection as such:
Columns.EntireColumn.Hidden = False
Rows.EntireRow.Hidden = False
You still have to iterate between the workbooks and to call the appropriate C# interop methods.
Upvotes: 1