从Excel列中读取数据超出范围异常 [英] Reading data from Excel Column out of range exception

查看:147
本文介绍了从Excel列中读取数据超出范围异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试构建一个应用程序来读取excel列中的所有信息,确定它是否包含一组信息,然后计算它在该列中重新出现的次数。具体而言,确定有多少项目是每天发货1,2,3或4
。这个小应用程序的原因是(我的配偶要求我做一个大声笑),但他使用非常大的ex​​cel文件,他通常必须通过excel的长期过程自己解决这个问题。无论如何,这是我现在的
和我得到的异常抛出,我超出范围,但我似乎无法弄清楚
为什么它将会消失范围。任何帮助将不胜感激,谢谢你提前。 

Hello, I am trying to build an app to read all the information from an excel column, determine if it contains a set of information, then count the number of times it reoccurs in that column. Specifically, how many items are determined to be 1, 2, 3, or 4 day ship times. The reason for this little app is that (well my spouse asked me to make one lol) but he works with really large excel files and he typically has to figure this out on his own through a long process in excel. Anyways, this is currently what I have and I am getting an exception thrown that I am out of range but I cannot seem to figure out why it is going to out of range. Any help would be greatly appreciated, thank you in advance. 

 Dim xlApp As Excel.Application
        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet
        Dim range As Excel.Range
        Dim rCnt As Integer
        Dim cCnt As Integer = whichShipColumn

        Dim day1 As Integer = 0
        Dim day2 As Integer = 0
        Dim day3 As Integer = 0
        Dim day4 As Integer = 0

        xlApp = New Excel.Application
        xlWorkBook = xlApp.Workbooks.Open(selectedFile)
        xlWorkSheet = xlWorkBook.Worksheets(1)
        range = xlWorkSheet.UsedRange


        Dim xlArray As System.Array = range.Value

        For rCnt = 1 To range.Rows.Count
            'This is where the exception is thrown
            Dim xlArVal As String = xlArray(rCnt, cCnt).ToString

            Select Case xlArVal
                Case xlArVal.ToString.Contains("1")
                    day1 += 1
                Case xlArVal.ToString.Contains("2")
                    day2 += 1
                Case xlArVal.ToString.Contains("3")
                    day3 += 1
                Case xlArVal.ToString.Contains("4")
                    day4 += 1

            End Select

        Next

推荐答案

您好ccr05,

Hi ccr05,

由于你的问题似乎与Excel有关,我将把这个帖子移到更相关的论坛。

参考:  https://social.msdn。 microsoft.com/Forums/enUS/home?forum=exceldev

Reference: https://social.msdn.microsoft.com/Forums/enUS/home?forum=exceldev

感谢您的理解和支持。

Thanks for your understanding and support.

最好的问候,

Neda Zhang

Neda Zhang


这篇关于从Excel列中读取数据超出范围异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆