DataGridView数据导出到Excel或者Word,该如何解决

DataGridView数据导出到Excel或者Word
谁能给个Vb.net下DataGridView数据导出到Excel或者Word的例子?

------解决方案--------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim dsEmployeeContract As DataSet = New DataSet
dsEmployeeContract.Clear()
dsEmployeeContract = ds

If dsEmployeeContract Is Nothing Then
MsgBox("没有数据,无法导出!", MsgBoxStyle.OKOnly)
Exit Sub
Else
Dim xlsapp As New Excel.Application
xlsapp.Workbooks.Add()
xlsapp.Visible = True
xlsapp.Range(xlsapp.Cells(1, 1), xlsapp.Cells(1, dsEmployeeContract.Tables(0).Columns.Count)).Select()
xlsapp.Selection.Merge()
xlsapp.Range(xlsapp.Cells(1, 1), xlsapp.Cells(1, 1)).Font.Size = 15
xlsapp.Range(xlsapp.Cells(1, 1), xlsapp.Cells(1, dsEmployeeContract.Tables(0).Columns.Count)).Font.Bold = True
Dim i As Int16
For i = 1 To dsEmployeeContract.Tables(0).Columns.Count
xlsapp.Cells(2, i) = dsEmployeeContract.Tables(0).Columns(i - 1).ColumnName
Next
Dim rowindex As Integer = 3
Dim colindex As Integer
Dim col As DataColumn
Dim row As DataRow
Dim nxh As Integer = 1
For Each row In dsEmployeeContract.Tables(0).Rows
colindex = 1
For Each col In dsEmployeeContract.Tables(0).Columns
If colindex = 1 Then
xlsapp.Cells(rowindex, colindex) = RTrim(Convert.ToString(row(col.ColumnName)))
Else
xlsapp.Cells(rowindex, colindex) = RTrim(Convert.ToString(row(col.ColumnName)))
End If
colindex += 1
Next
rowindex += 1
nxh += 1
Next
xlsapp.Columns.AutoFit()
End If
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Critical)
End Try
End Sub
ds为Public ds As DataSet = New DataSet,是你DataGridView数据
------解决方案--------------------
Public QueryTable As DataTable
Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
Dim xlApp As Excel.Application '定义EXCEL类
Dim xlBook As Excel.Workbook '定义工件簿类
Dim xlsheet As Excel.Worksheet '定义工作表类
Dim Fieldlen
Dim Irow As Integer = 0 : Dim Icol As Integer = 0
Dim IrowCount As Integer = 0 : Dim IcolCount As Integer = 0
Dim ExcelName As String

xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
xlBook = xlApp.Workbooks.Add 'Open("H:\shock\sales\temp\bb.xls") '打开EXCEL工作簿
xlsheet = xlBook.Worksheets(1) '打开EXCEL工作表

IrowCount = QueryTable.Rows.Count '总行数
IcolCount = QueryTable.Columns.Count '总列数
ReDim Fieldlen(IcolCount)

ExcelName = Trim(labBT.Text)
xlApp.Caption = ExcelName & "表"
xlApp.Cells(1, 2) = ExcelName & "表"
xlApp.Range("B1:G2").MergeCells = True '合并单元格

Dim Col As DataColumn
Dim Row As DataRow
For Each Col In QueryTable.Columns
Icol = Icol + 1
xlApp.Cells(4, Icol + 1) = Col.ColumnName
Next

'得到的表所有行,赋值给单元格

For Each Row In QueryTable.Rows