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 If sheet(0, i).Text > "" Then colNames.Add(sheet(0, i).Text) Else messagebox.show("Excel文件的第" & (i+1) & "列的列名为空,要罢工") Return End If Next 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 ndr(colNames(j)) = sheet(i, j).Text Next End If Next End If
|