Vb.net 从excel导入到列表框
尝试将列从excel导入vb.net表单中的列表框时出现中断错误 问题是在将列中的所有项成功导入列表框之后。出现中断错误并关闭程序。 这是中断错误Vb.net 从excel导入到列表框,vb.net,excel,listbox,importerror,import-from-excel,Vb.net,Excel,Listbox,Importerror,Import From Excel,尝试将列从excel导入vb.net表单中的列表框时出现中断错误 问题是在将列中的所有项成功导入列表框之后。出现中断错误并关闭程序。 这是中断错误 An unhandled exception of type 'System.ArgumentNullException' occurred in System.Windows.Forms.dll Additional information: Value cannot be null)) 这是我的密码
An unhandled exception of type 'System.ArgumentNullException' occurred
in System.Windows.Forms.dll
Additional information: Value cannot be null))
这是我的密码
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim oExcel As Object = CreateObject("Excel.Application")
Dim oBook As Object = oExcel.Workbooks.Open("C:\Users\User\Desktop\1.xlsx")
Dim oSheet As Object = oBook.Worksheets(1)
Dim i As Integer
Dim cell As String
For i = 0 To AscW(ListBox1.Items.Count.ToString()(i = i + 1))
cell = "E" & Convert.ToString(i + 1)
cell = oSheet.Range(cell).Value
ListBox1.Items.Add(cell)
Next
oExcel.Quit()
End Sub
您能否测试
cell=oSheet.Range(cell.Value
之后的单元格是否为空?您能否解释更多内容请在将cell
添加到ListBox1 Items集合之前测试其值。我测试了。但同样的错误也会发生。当你在调试器中单步执行代码时,错误会发生在哪一行?你能测试一下cell=oSheet.Range(cell.Value
)之后的单元格是否为空吗?你能解释一下吗?在将cell
添加到ListBox1 Items集合之前,请先测试一下它的值。我做了。但同样的错误也会发生。如果您在调试器中单步执行代码,错误会发生在哪一行?