先在: My Project 中引用 Microsoft Excel 11.0 Object Library(这个是Excel 2003,Excel 2007 是12.0),之后在窗体代码中加入相关内容就行了。以下是一个窗体的简单实例 假设在C盘根文件夹中有:TEST.xls Public Class 引用EXCEL窗体 Private A() As String = {"A", "B", "CC", "C", "D"} Private B() As Integer = {1, 22, 34, 50, 16, 99, 14} Private excelapp As New Microsoft.Office.Interop.Excel.Application Private excelworkbook As Microsoft.Office.Interop.Excel.Workbook
Private Sub 引用EXCEL_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim Index As Integer excelworkbook = excelapp.Workbooks.Open("c:\test.xls") excelapp.Application.Workbooks.Add(True) excelapp.Cells(1, 1) = "数组:A" For Index = 0 To UBound(A) excelapp.Cells(Index + 2, 1) = A(Index) Next excelapp.Cells(1, 2) = "数组:B" For Index = 0 To UBound(B) excelapp.Cells(Index + 2, 2) = B(Index) Next excelapp.Visible = True End Sub End Class