Imports System.Runtime.InteropServices.Marshal
Imports Office
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'以COM方式处理Excel
Dim oExcel As New Excel.Application
Dim oBooks As Excel.Workbooks, oBook As Excel.Workbook
Dim oSheets As Excel.Sheets, oSheet As Excel.Worksheet
Dim oCells As Excel.Range
Dim sFile As String, sTemplate As String
'定义一个datatable
Dim dt As DataTable = CType(Application.Item("MyDataTable"), DataTable)
'将DATATABLE的内容导出到Excel的单元格中去
Private Function DumpData(ByVal dt As DataTable, ByVal oCells As Excel.Range) As String
Dim dr As DataRow, ary() As Object
Dim iRow As Integer, iCol As Integer
'输出列标题
For iCol = 0 To dt.Columns.Count - 1
oCells(2, iCol + 1) = dt.Columns(iCol).ToString
Next
'将数据导出到相应的单元格
For iRow = 0 To dt.Rows.Count - 1
dr = dt.Rows.Item(iRow)
ary = dr.ItemArray
For iCol = 0 To UBound(ary)
oCells(iRow + 3, iCol + 1) = ary(iCol).ToString
Response.Write(ary(iCol).ToString & vbTab)
Next
Next
End Function
End Class
我用这种方法成功导出过,你要在你项目的根目录下建立一个excel的文件就好了,作为摸版,把你要的数据导入dataset的表中就好了,搂主可以试一下!!