public sub form_load()
dim n_shuzi as integer
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim shuzu(3) As Integer
Dim n_shuzi As Integer
Public f_row As Integer
Public m_row As Integer
xlapp = New Excel.Application
xlbook = xlapp.Workbooks.Open(“D:\123.clsx”)
xlapp.Visible = True
xlsheet = xlbook.Worksheets("Sheet1")
n_shuzi = xlsheet.Cells(1, 1)
For f_row = 0 To 3
shuzu(f_row) = xlsheet.Cells(f_row + 1, 1)
Next
如上面所示程序 从123.xlsx中读取数据 写入数组中 把cells(1,1)的数值赋给参数n_shuzi,即就是n_shuzi=xlsheet.cells(1,1)到这快就会出现
InvalidCastException was unhandled 这是什么错误?请大师帮忙解决
大师 问题解决了 谢谢啊 还是使用最后一句加上.value 嘿嘿 3Q
追答不客气,能得到正解就好。
改成上面你说的之后 n_shuzi=val(xlsheet.cells(1,1))还是报Argument 'Expression' cannot be converted to type 'Range'.这个错误 我把改成n_shuzi=val(“xlsheet.cells(1,1)")后不报错了 但是n_shuzi就是没有值 我Excel表格中给A1的值是2,大师为什么?
本回答被提问者采纳大师 改成你所写的之后 错误又报 ArgumentException was unhandled (argument 'Expression' cannot be converted to type 'Range')