亲宝软件园·资讯

展开

C# 判断Excel工作表中的指定行或列是否隐藏(附VB.NET代码)

TO BE 人气:0

本文中,以C#代码展示如何判断Excel工作表中的行或者列是否设置了隐藏。附VB.NET代码供参考。

程序运行环境

● Visual Studio

● .Net framework 4.8

● Excel测试文档:.xlsx 2013

● Excel工具类库:spire.xls.dll 11.6

dll文件引用:可通过nuget网站下载安装,或者在spire网站下载安装。引用结果如图所示:

C#

using Spire.Xls;

 

namespace DetectHiddenRowOrColumn_XLS

{

    class Program

    {

        static void Main(string[] args)

        {

            //加载Excel工作簿

            Workbook wb = new Workbook();

            wb.LoadFromFile("sample.xlsx");

 

            //获取第一张工作表

            Worksheet sheet = wb.Worksheets[0];

 

            //判断第3行是否隐藏

            bool result = sheet.GetRowIsHide(3);

            //sheet.GetColumnIsHide(5);//判断第5列是否隐藏

 

            if (result == true)

            {               

                System.Console.WriteLine("隐藏");

                System.Console.ReadLine();

            }

            else

            {

                System.Console.WriteLine("未隐藏");

                System.Console.ReadLine();

            }

         

        }

    }

}

 

VB.NET

Imports Spire.Xls

 

Namespace DetectHiddenRowOrColumn_XLS

         Class Program

                   Private Shared Sub Main(args As String())

                            '加载Excel工作簿

                            Dim wb As New Workbook()

                            wb.LoadFromFile("sample.xlsx")

 

                            '获取第一张工作表

                            Dim sheet As Worksheet = wb.Worksheets(0)

 

                            '判断第3行是否隐藏

                            Dim result As Boolean = sheet.GetRowIsHide(3)

                            'sheet.GetColumnIsHide(5); '判断第5列是否隐藏

 

                            If result = True Then

                                     System.Console.WriteLine("隐藏")

                                     System.Console.ReadLine()

                            Else

                                     System.Console.WriteLine("未隐藏")

                                     System.Console.ReadLine()

                            End If

 

                   End Sub

         End Class

End Namespace

Excel测试文档如图,隐藏了第三行和第五列:

判断结果:

—End—

加载全部内容

相关教程
猜你喜欢
用户评论