Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(ProjectPath & "EXCEL测试文件\" & "test20.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim rowsmax As Integer = 0
Dim colmax As Integer = 0
Dim rg = Ws.UsedRange
'Dim FirstRow As Integer = Ws.Range("A1:d1").End(MSExcel.XlDirection.xlDown).Row
'msgbox(firstrow)
For i As Integer =1 To rg.Columns.count
Dim r = ws.cells(1000,i).End(MsExcel.XlDirection.xlUp).Row
If r > RowsMax Then
RowsMax = r
End If
Next
For i As Integer = 1 To rowsMax
Dim r = ws.cells(i,200).End(MsExcel.XLDirection.xlToLeft).Column
If r > ColMax Then
ColMax = r
End If
Next
rg = Ws.Range(Ws.Cells(1,1), Ws.Cells(RowsMax,ColMax ))
Dim ary = rg.value
'msgbox(rg.Rows.count)
'msgbox("读取列:" & rg.Columns.count & "," & "实际列:" & ColMax & "," & "实际行:" & RowsMax )
For i As Integer = 1 To rowsmax
For j As Integer = 1 To Colmax
If ary(i,j) <> Nothing Then
Dim dr As DataRow = DataTables("表A").AddNew
dr("第一列") = ary(i, j)
End If
Next
Next
App.quit
'msgbox(colsmax)
'msgbox(RowsMax)