prototype0815
prototype0815

Reputation: 620

Unhide all Hidden Excel Columns Without Individual Iteration?

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

Answers (1)

ΩmegaMan
ΩmegaMan

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

Related Questions