Dim dlg As new OpenFileDialog dlg.Filter = "Excel|*.xls" If dlg.ShowDialog = DialogResult.OK Then Dim App As New MSExcel.Application try Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(dlg.FileName) Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1) Dim Rg As MSExcel.Range = Ws.UsedRange Dim ary = rg.value Dim nms() As String = {"", "招标人代理机构代码", "项目经办人","标段编号", "标段名称", "", "开标日期"} DataTables("表A").StopRedraw For n As Integer = 3 To rg.Rows.Count Dim ro As Row = Tables("表A").AddNew For i As Integer = 0 To nms.length - 1 If nms(i)>"" Then If ary(n,i+1) <> Nothing Then ro(nms(i)) = cstr(ary(n,i+1)).trim ElseIf n > 3 AndAlso ary(n-1,i) <> Nothing Then ro(nms(i)) = cstr(ary(n-1,i+1)).trim End If End If Next Next MessageBox.Show("导入成功!","恭喜!") catch ex As exception msgbox(ex.message) MessageBox.Show("导入失败!","恭喜!") finally DataTables("表A").ResumeRedraw app.quit End try End If
|