DataTables("翻译内容").StopRedraw
Dim app As new MSExcel.Application
app.DisplayAlerts= False '不显示EXCEL警示
Dim excelcol As Integer
Dim excelrows As Integer
If file.EndsWith(".xls") OrElse file.EndsWith(".XLS") OrElse file.EndsWith(".xlsx") OrElse file.EndsWith(".XLSX") Then
If file.EndsWith(".xls") OrElse file.EndsWith(".XLS") Then
excelcol = 256
excelrows =65536
Else
excelcol = 16384
excelrows =1048576
End If
Dim wb As MsExcel.WorkBook
Dim WS As MsExcel.WorkSheet
try
wb=app.WorkBooks.open(file)
For k As Integer=1 To wb.worksheets.Count
Ws=Wb.WorkSheets(k)
Dim Rg As MSExcel.Range = Ws.UsedRange
'lbl9.text = "Sheet名称:" & " " & Ws.name
If rg.Count = 1 And rg(1).Value Is Nothing Then
Continue For
End If
If Numcb2.Text = Nothing And Numcb3.Text = Nothing Then
RowsMax = 0
ColsMax = 0
'获取最大行
For i As Integer = 1 To rg.Columns.count
Dim r = ws.cells(excelrows,i).End(MsExcel.XlDirection.xlUp).Row
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,excelcol).End(MsExcel.XlDirection.xlToLeft).Column
If r > ColsMax Then
ColsMax = r
End If
Next
If Rowsmax=1 And ColsMax=1 Then '解决只有一行一列数据时报错问题
InputValue(Rowsmax, "提示", ws.name & "输入最大行数:")
InputValue(ColsMax, "提示", ws.name & "输入最大列数:")
End If
Else
RowsMax = Numcb2.Value
ColsMax = Numcb3.Value
'Output.Show("ColsMax =" & ColsMax )
End If
'lbl8.text ="有效行列:" & " " & RowsMax & "," & Colsmax
rg = Ws.Range(Ws.Cells(1,1), Ws.Cells(RowsMax,ColsMax))
'output.show("rg.Count:" & rg.count)
Dim ary = rg.value
For i As Integer=1 To RowsMax
If CBox2.Checked OrElse rg.Rows(i).height <> 0 Then
For j As Integer = 1 To Colsmax
If CBox2.Checked OrElse rg.Columns(j).width <> 0 Then '提隐藏行
If ary(i,j) <> Nothing Then
If CBox1.Checked = False OrElse CBox1.Checked = True AndAlso System.Text.RegularExpressions.Regex.Match(ary(i,j),"[\u4e00-\u9fa5]+").Tostring()>"" '提中文
Dim dr As DataRow = DataTables("Table1").AddNew
dr("listfile") = ary(i, j)
'lbl5.text ="提取内容:" & ary(i,j)
'Application.DoEvents
End If
End If
End If
Next
Else
txt5.text =file & "(" & Ws.name & ")" & vbcrlf & txt5.text & vbcrlf
End If
Next
Next
Catch ex As Exception
Dim txt2 As WinForm.TextBox = Forms("提取工具").Controls("TextBox4")
txt2.text = file & vbcrlf & txt2.text & vbcrlf
BadFileCount =BadFileCount +1
msgbox(ex.message)
finally
If ws IsNot Nothing Then ws = Nothing
If Wb IsNot Nothing Then Wb.Close(Type.Missing, Type.Missing, Type.Missing)
If Wb IsNot Nothing Then Wb = Nothing
End try
End If
'Next
DataTables("Table1").ResumeRedraw
app.quit()