Dim dlg As New OpenFileDialog
dlg.Filter= "Excel文件|*.xls;*.xlsx"
If dlg.ShowDialog = DialogResult.Ok Then
'MessageBox.Show("你选择的是:" & dlg.FileName,"提示")
Dim Book As New XLS.Book(dlg.FileName)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Dim colNames As New List(Of String)
For i As Integer = 0 To sheet.Cols.Count - 1
colNames.Add(sheet(0, i).Text)
Next
MessageBox.Show(“这里上面的代码没问题”)
Dim dt As DataTable = DataTables("机电设备表")
For i As Integer = 1 To sheet.Rows.Count - 1
If dt.Find("序号 = '" & sheet(i, 0).Text & "'") Is Nothing Then
Dim ndr As DataRow = dt.AddNew
For j As Integer = 0 To sheet.Cols.Count - 1
MessageBox.Show(colNames(j))
MessageBox.Show(sheet(i, j).Text)
ndr(colNames(j)) = sheet(i, j).Text
Next
End If
Next
End If
MessageBox.Show()