tags:

views:

106

answers:

1

Hi all,

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

A: 

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
Tim Murphy