|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
在VSTO中用VB.net,开发软件过程中提示如下语句出现错误:
xlsbook = xlsApp.Workbooks.Open("C:\Program Files (x86) \sldata.xlsx")
在这一句报警,
立即窗口出现提示:“在 System.Runtime.InteropServices.COMException 中第一次偶然出现的“测试.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
复制代码
|
-
-
-
测试.rar
1.57 MB, 下载次数: 13
出错的项目文件
|