关于vb.net导出excel的问题
在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"或它的某一个依赖项.系统找不到指定的文件..