下列代码执行一个EXCEL文件中有50个多SHEET时报错“存储空间不足”的错误,检查硬盘及内容都有富余并未不足,请老师帮助看看是哪里的代码有问题?
Dim st As Date = Date.Now
Dim lbl As WinForm.Label = Forms("窗口1").Controls("Label6")
Dim lbl8 As WinForm.Label = Forms("窗口1").Controls("Label8")
Dim lbl9 As WinForm.Label = Forms("窗口1").Controls("Label9")
Dim val As WinForm.NumericComboBox = Forms("窗口1").Controls("NumericComboBox1")
Dim path As String = args(0)
Dim file As Object
Dim app As new MSExcel.Application
'app.visible = True
'//准备字典信息
'try
Dim dic As new Dictionary(of String,String)
Dim dicfile As String = Forms("窗口1").Controls("TextBox2").value
Dim Book As New XLS.Book(dicfile) '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
For i As Integer = 0 To Sheet.Rows.Count-1
If dic.ContainsKey(Sheet(i, 0).Text.ToLower.Replace(" ","").Replace(chr(10), "").Replace(chr(13), "")) = False Then
dic.add(Sheet(i, 0).Text.ToLower.Replace(" ","").Replace(chr(10), "").Replace(chr(13), ""),Sheet(i, 1).Text)
End If
Next
'--------------------
'//开始翻译
For Each file In FileSys.GetFiles(path)
'try
If file.EndsWith(".xls") OrElse file.EndsWith(".xlsx") Then
Dim wb=app.WorkBooks.open(file)
For k As Integer=1 To wb.worksheets.Count
Dim Ws As MSExcel.WorkSheet=Wb.WorkSheets(k)
Dim rg As MSExcel.Range=Ws.UsedRange
If rg.Count = 1 And rg(1).Value = "" Then
Continue For
End If
Dim ary = rg.value
For i As Integer=1 To rg.Rows.count
'If rg.Rows(i).height<> 0 Then
'For i As Integer = 0 To Sheet1.Rows.Count-1
' If sheet1.Rows(i).height <> 0=True Then
For j As Integer = 1 To rg.Columns.Count
'If rg.Columns(j).width <> 0 Then
If ary(i, j) <> Nothing AndAlso Typeof ary(i,j) Is String AndAlso dic.ContainsKey(ary(i,j).ToLower.Replace(" ","").Replace(chr(10), "").Replace(chr(13), "")) Then
If Forms("窗口1").Controls("RBt5").checked Then
'纯译文=真
'Sheet1(i, j).Value = dic(Sheet1(i, j).Text.ToLower.Replace(" ","").Replace(chr(10), "").Replace(chr(13), ""))
rg(i, j).Value= dic(ary(i,j).ToLower.Replace(" ","").Replace(chr(10), "").Replace(chr(13), ""))
lbl8.text=dic(ary(i,j).ToLower.Replace(" ","").Replace(chr(10), "").Replace(chr(13), ""))
Else If Forms("窗口1").Controls("RBt6").checked Then '对照=真
If Forms("窗口1").Controls("RBt1").checked Then
'对照+竖线
'msgbox(rg(i, j).Value)
output.show(rg(i, j).Value)
rg(i, j).Value= ary(i,j) & "|" & dic(ary(i,j).ToLower.Replace(" ","").Replace(chr(10), "").Replace(chr(13), ""))
'lbl8.text=ary(i,j) & "|" & dic(ary(i,j).ToLower.Replace(" ","").Replace(chr(10), "").Replace(chr(13), ""))
Else If Forms("窗口1").Controls("RBt2").checked=True Then
'对照+回车
rg(i, j).Value= ary(i,j) & vbcrlf & dic(ary(i,j).ToLower.Replace(" ","").Replace(chr(10), "").Replace(chr(13), ""))
lbl8.text=ary(i,j) & vbcrlf & dic(ary(i,j).ToLower.Replace(" ","").Replace(chr(10), "").Replace(chr(13), ""))
Else If Forms("窗口1").Controls("RBt4").checked=True Then
'对照+右列
rg(i, j).Value = ary(i,j)
rg(i,j+1).value = dic(ary(i,j).ToLower.Replace(" ","").Replace(chr(10), "").Replace(chr(13), ""))
'错误ws.Cells(i,j+1).value = dic(ary(i,j).ToLower.Replace(" ","").Replace(chr(10), "").Replace(chr(13), ""))
lbl8.text=ary(i,j) & "+" & dic(ary(i,j).ToLower.Replace(" ","").Replace(chr(10), "").Replace(chr(13), ""))
End If
End If
End If
' End If
Next
'End If
Next
Next
output.show(3)
Dim txt1 As WinForm.TextBox = Forms("窗口1").Controls("TextBox3")
txt1.text = file & vbcrlf & txt1.text & vbcrlf
Application.DoEvents()
FileCount=FileCount+1
lbl.Text="共处理" & FileCount & "个文件"
wb.Save
app.quit
End If
Next
For Each p As String In FileSys.GetDirectories(path)
Functions.Execute("函数1", p)
Next
lbl9.Text="计算结束, 耗时: " & (Date.Now - st).TotalSeconds & "秒"