红色代码有问题,可以删除。
Dim dlg As new OpenFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx"
If dlg.ShowDialog = DialogResult.OK Then
If FileIsOpened( dlg.FileName )= True Then
MessageBox.Show("请关闭文件后重新导入!")
e.Form.Close
Else
If Connections.Contains("test") Then
If DataTables.Contains("临时表") Then DataTables.Unload("临时表")
Connections.Delete("test")
Else
e.Form.Close
End If
Connections.Add("test", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dlg.FileName & ";Extended Properties='Excel 8.0;HDR=yes'")
Dim tns As String = ""
For Each tn As String In Connections("test").GetTableNames
tns &= tn & "|"
Next
e.Form.Controls("ComboBox1").ComboList = tns.TrimEnd("|")
e.Form.Controls("ComboBox1").Selectedindex = 0
End If
Else
e.Form.Close
End If