Dim dt As DataTable = DataTables("金华销售")
Dim Result As DialogResult
Result = MessageBox.Show("确定要导入吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes Then
Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xls"
dlg.MultiSelect = True '允许选择多个文件
If dlg.ShowDialog =DialogResult.OK Then
Dim Book As New XLS.Book(dlg.FileName)
Dim Sheet As XLS.Sheet = Book.Sheets("3.1全")
dt.ResumeRedraw()
dt.StopRedraw()
'systemready = False
Dim nms As New Dictionary(Of String, Integer)
Dim dic As new Dictionary(Of DataRow, Integer)
Dim ls As new List(Of Integer)
For c As Integer = 0 To sheet.Cols.Count - 1
If dt.DataCols.Contains(sheet(0,c).Text.replace(" ", "")) Then
nms.Add(sheet(0,c).Text.replace(" ", ""), c)
End If
Next
For l As Integer = 1 To Sheet.Rows.Count -1
Dim ndr As DataRow = dt.AddNew
For Each m As String In nms.keys
If dt.DataCols(m).IsBoolean Then
If Sheet(l,nms(m)).Text = "" OrElse Sheet(l,nms(m)).Text = "False" OrElse Sheet(l,nms(m)).Value = 0 Then
ndr (m) = False
Else
ndr (m) = True
End If
Else If dt.DataCols(m).Expression > "" Then
'表达式列
Else If dt.DataCols(m).IsNumeric Then
ndr (m) = val(Sheet(l,nms(m)).Value)
Else If dt.DataCols(m).IsDate Then
Dim d As Date
If Date.TryParse(Sheet(l,nms(m)).Value, d)
ndr (m) = d
End If
Else
ndr (m) = Sheet(l,nms(m)).Value
End If
Next
Next
dt.ResumeRedraw()
'systemready = True
End If
End If