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 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
'Dim excelcol As Integer
'Dim excelrows As Integer
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 RowsMax As Integer = 0
'Dim ColsMax As Integer = 0
Dim ColsMax As Integer = ws.UsedRange.columns.count
'Dim ColsMax As Integer = ws.UsedRange.columns.count
Output.Show("ws.UsedRange.columns.count=" & ColsMax )
'获取最大行
For i As Integer = 1 To ColsMax
Dim r = ws.cells(1048576,i).End(MsExcel.XlDirection.xlUp).Row '扩展名为XLSX的文件最大行为1048576
If r > RowsMax Then
RowsMax = r
End If
Next
Output.Show("rowsmax =" & rowsmax )
'获取最大列
For i As Integer = 1 To RowsMax
Dim r = ws.cells(i,16384).End(MsExcel.XlDirection.xlToLeft).Column '扩展名为XLSX的文件最大列为16384
If r > ColsMax Then
ColsMax = r
End If
Next
Output.Show("ColsMax =" & ColsMax )
'Output.Show(ws.UsedRange.Rows.count)
Dim rg As MSExcel.Range = Ws.Range(Ws.Cells(1,1), Ws.Cells(RowsMax,ColsMax))
'Dim rg As MSExcel.Range=Ws.UsedRange
If rg.Count = 1 And rg(1).Value = "" Then
Continue For
End If
Dim idx As Integer = 1
Do While True
If idx > Rowsmax Then Exit Do
Dim max As Integer = iif(idx+1000>Rowsmax, Rowsmax, idx+1000)
rg = Ws.Range(Ws.Cells(idx,1), Ws.Cells(max,ColsMax))
Dim ary = rg.value
Output.Show("ary ok")
For i As Integer= 1 To rg.Rows.count
For j As Integer = 1 To ColsMax
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
rg(i, j).Value= ary(i,j) & "|" & dic(ary(i,j).ToLower.Replace(" ","").Replace(chr(10), "").Replace(chr(13), ""))
End If
Next
Next
idx = max+1
Loop
Next
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
End If
Next
app.quit
For Each p As String In FileSys.GetDirectories(path)
Functions.Execute("处理隐藏列", p)
Next
lbl9.Text="计算结束, 耗时: " & (Date.Now - st).TotalSeconds & "秒"