find out if there are hidden columns in excel

筅森魡賤 提交于 2019-12-12 22:13:54

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/3066200/find-out-if-there-are-hidden-columns-in-excel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!