关于vb.net导出excel的问题

xixi125 2008-11-11 12:07:31
在vb.net中点一个按钮导出datagridview中的数据到excel
代码如下,我在程序中能运行正常,但生成一个.exe再运行时就会报错,请问各位高手怎么解决

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ex As New Excel.Application
ex.Visible = True
ex.Workbooks.Add()
ex.Cells(1, 1) = "期号"
ex.Cells(1, 2) = "征订号"
ex.Cells(1, 3) = "书名"
ex.Cells(1, 4) = "估价"
ex.Cells(1, 5) = "年级"
ex.Cells(1, 6) = "科目"
ex.Cells(1, 7) = "版别"
ex.Cells(1, 8) = "出版日期"
ex.Cells(1, 9) = "类别"
ex.Cells(1, 10) = "数量"
i = 0
j = Me.DataGridView1.Rows.Count
If j = 0 Then
Exit Sub
End If

Do While (i < j)
ex.Cells(i + 2, 1) = Me.DataGridView1.Rows(i).Cells(9).Value
ex.Cells(i + 2, 2) = Me.DataGridView1.Rows(i).Cells(10).Value
ex.Cells(i + 2, 3) = Me.DataGridView1.Rows(i).Cells(11).Value
ex.Cells(i + 2, 4) = Me.DataGridView1.Rows(i).Cells(12).Value
ex.Cells(i + 2, 5) = Me.DataGridView1.Rows(i).Cells(13).Value
ex.Cells(i + 2, 6) = Me.DataGridView1.Rows(i).Cells(14).Value
ex.Cells(i + 2, 7) = Me.DataGridView1.Rows(i).Cells(15).Value
ex.Cells(i + 2, 8) = Me.DataGridView1.Rows(i).Cells(16).Value
ex.Cells(i + 2, 9) = Me.DataGridView1.Rows(i).Cells(17).Value

i = i + 1
Loop
End Sub



生成.exe后报错如下:

为能加载文件或程序集"interop.excel,version=1.3.0.0,culture=neutral,publickeytoken=null"或它的某一个依赖项.系统找不到指定的文件..

...全文
236 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xixi125 2008-11-11
  • 打赏
  • 举报
回复
感谢楼上两位
wadialin:多谢你的提醒,我生成.exe后没有把Interop.Excel.dll ,Interop.Office.dll这几个dll文件一起拷走.
哈哈,搞定了,去结贴
yangmt204 2008-11-11
  • 打赏
  • 举报
回复
up
ejoe313 2008-11-11
  • 打赏
  • 举报
回复
添加引用-->COM-->MicroSoft Excel 11.0 Object Library
wadialin 2008-11-11
  • 打赏
  • 举报
回复
你引用 Interop.Excel 了吗?

还要再导入包

看看 Bin\Debug 是否有Interop.Excel.dll 这个文件?

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧