xlsbook = xlsApp.Workbooks.Open("C:\Program Files (x86) \sldata.xlsx")
在这一句报警,
立即窗口出现提示:“在 System.Runtime. 中第一次偶然出现的“测试.exe”类型的异常”
网上搜了很多资料都没有解决问题,请论坛里的老师给帮忙看看,指点一下,谢谢!
具体代码和出错的项目文件附下:
程序代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'读取并释放资源文件
Dim resources As System.Resources.ResourceManager = My.Resources.ResourceManager
Dim res() As Byte = resources.GetObject("sldata")
Dim myfile As New IO.FileStream("C:\Program Files (x86) \sldata.xlsx", IO.FileMode.OpenOrCreate)
myfile.Write(res, 0, res.Length)
myfile.Close()
Dim xlsApp As Microsoft.Office.Interop.Excel.Application '声明对象变量
Dim xlsbook As Microsoft.Office.Interop.Excel.Workbook
Dim xlssheet As Microsoft.Office.Interop.Excel.Worksheet
Dim C
xlsApp = New Microsoft.Office.Interop.Excel.Application '实例化对象
xlsbook = xlsApp.Workbooks.Open("C:\Program Files (x86) \sldata.xlsx") '打开EXCEL文件
xlssheet = xlsbook.Worksheets("WO")
C = xlssheet.Range("a:a").Find("B3SH10")
xlsApp.Visible = False '使Excel隐藏不可见
TextBox1.Text = C
End Sub
'读取并释放资源文件
Dim resources As System.Resources.ResourceManager = My.Resources.ResourceManager
Dim res() As Byte = resources.GetObject("sldata")
Dim myfile As New IO.FileStream("C:\Program Files (x86) \sldata.xlsx", IO.FileMode.OpenOrCreate)
myfile.Write(res, 0, res.Length)
myfile.Close()
Dim xlsApp As Microsoft.Office.Interop.Excel.Application '声明对象变量
Dim xlsbook As Microsoft.Office.Interop.Excel.Workbook
Dim xlssheet As Microsoft.Office.Interop.Excel.Worksheet
Dim C
xlsApp = New Microsoft.Office.Interop.Excel.Application '实例化对象
xlsbook = xlsApp.Workbooks.Open("C:\Program Files (x86) \sldata.xlsx") '打开EXCEL文件
xlssheet = xlsbook.Worksheets("WO")
C = xlssheet.Range("a:a").Find("B3SH10")
xlsApp.Visible = False '使Excel隐藏不可见
TextBox1.Text = C
End Sub
只有本站会员才能查看附件,请 登录