ps.
ps.

Reputation: 4360

find out if there are hidden columns in excel

I need to know if there hidden columns in the excel sheet.

i used use the following which worked fine and then suddenly it stopped working.now it always returns false.

bool.Parse(worksheet.PageSetup.Application.Columns.Hidden.ToString())

TIA excel 2007 .net 3.5

Upvotes: 2

Views: 2966

Answers (1)

Tim Murphy
Tim Murphy

Reputation: 4932

Refactor the following snippet of code as required.

Option Strict Off

Imports System
Imports System.Console
Imports Microsoft.Office.Interop

Public Class AreThereHiddenColumnsInExcelWorkSheet

    Public Shared Sub Execute()

        Dim excel = New Excel.Application

        excel.Visible = True
        excel.Workbooks.Add()
        excel.Columns("C:C").Select()
        excel.Selection.EntireColumn.Hidden = True

        Dim columns = excel.Columns
        Dim hasHiddenColumns As Boolean

        For Each column In columns
            If column.Hidden Then
                hasHiddenColumns = True
                Exit For
            End If
        Next

        WriteLine("excel.Columns.Hidden = " + hasHiddenColumns.ToString())

    End Sub

End Class

Upvotes: 2

Related Questions