从外部表EXL导入数据(导入代码如下:),为何出现:“索引超出范围。必须为非负值并小于集合大小。” 参数名:index
怎么也查不出原因,其他外表都可以,到底怎么回事?请教老师,谢谢!
代码:
此主题相关图片如下:出错截图.jpg
For Each file As String In filesys .GetFiles("D:\百度云同步盘\丽水\数据\市公司财务") '获取该目录下的所有文件集
If file.EndsWith(".xls") OrElse file.EndsWith(".xlsx") Then
Dim Book As New XLS.Book(file)
Dim Sheet As XLS.Sheet = Book.Sheets("全市储蓄分钟类表") '打开"储蓄"工作表
' Tables("网点分储种余额").StopRedraw()
' Dim nms() As String = {"日期","机构代码","县","网点简称","合计","活期","通知存款","定活两便","定期","其中大额存单"}
Dim rq1 As String = sheet(3,9).text
Dim rq_y As String = left(rq1.trim(" "),4)
Dim rq_m As Integer =iif(rq1.length <= 7,rq1.SubString(5,1),rq1.SubString(5,2))
Dim Days As Integer = Date.DaysInMonth(rq_y,rq_m) '取该月天数
Dim rq As Date = New Date(rq_y,rq_m,Days) '取该月日期
MessageBox.show("年=[ " & rq_y & "] 月=[" & rq_m & "] 地市名称=[ & dw_s & ] 类别= [ & LB & ],!","警告!",messageboxbuttons.ok)
Return
Dim dw As String = sheet(3,0).Text '取市级[单位名称]栏数据
Dim dw_s As String = dw.substring(5,3) '选取市级名称 'iif(right(dw.trim(""),2) = "汇总",left(dw,2)," ") '判断是否汇总栏?
Dim LB As String =dw.Substring(15,2) '选取代理 还是 自营
'dw=iif(right(dw,2) = "汇总","汇总",left(dw,1)+right(dw,1)) 'trim(" ") '去掉空格
If IsDate(rq) Then '确定表达式expression能否转换成日期格式. len(rq1.trim(" ")) = 10 And
Else
MessageBox.show("日期[" & rq & "]格式错误,请在3行9列按[YYYY-MM-DD]重输!","警告!",messageboxbuttons.ok)
Return
End If
Dim js As Integer = 1
For n As Integer = 6 To Sheet.Rows.Count -1
dw = sheet(n,0).Text '取[单位名称]栏数据
dw = dw.trim(" ")
dw=iif(left(dw,2) = "丽水","市本级",iif(left(dw,2) = "景宁",left(dw,7),left(dw,3)))
Dim dr As DataRow = DataTables("全市分储种余额").Find("日期 = " & rq & " And 市 = '" & dw_s & "' and 县 = '" & dw & "'")
If ( dr Is Nothing Or dr IsNot Nothing ) And dw <> "" Then '如果不存在同日期与机构代码的,将增加数据(自动过滤机构代码为空的行数)
If dr Is Nothing Then
dr = DataTables("全市分储种余额").AddNew()
dr("日期") = rq
dr("市") = dw_s
dr("县") = dw
dr("板块") = LB 'iif(e.Form.Controls("RadioButton1").Checked = True,"代理","自营") 'RadioButton1
End If
If ( n > =10 And n <= 18) Then
dr("存款余额") = sheet(n,1).text '期末余额
dr("活期余额") = sheet(n,2).text '活期
dr("定活两便") = sheet(n,5).text '定活两便
dr("个人通知存款") = sheet(n,7).text '个人通知
dr("DQ00") = sheet(n,9).text '定期余额
dr("DQ0301") = sheet(n,18).text '三个月不含协议
dr("DQ0302") = sheet(n,20).text '三个月协议
dr("DQ0601") = sheet(n,28).text '六个月不含协议
dr("DQ0602") = sheet(n,30).text '六个月协议
dr("DQ1201") = sheet(n+15,3).text '一年不含协议
dr("DQ1202") = sheet(n+15,5).text '一年协议
dr("DQ2401") = sheet(n+15,17).text '二年不含协议
dr("DQ2402") = sheet(n+15,19).text '二年协议
dr("DQ3601") = sheet(n+15,27).text '三年不含协议
dr("DQ3602") = sheet(n+15,29).text '三年协议
dr("DQ6001") = sheet(n+15,37).text '五年不含协议
dr("DQ6002") = sheet(n+15,39).text '五年协议
End If
application.Doevents '即刻暂停代码的执行,重新绘制控件后,继续执行代码.
End If
Next
End If
Output.Show(File)
Next
'End If
Tables("全市分储种余额").ResumeRedraw()
DataTables("全市分储种余额").save