直接在工作表的首行追加2行就可以了啊,你也可以直接选择我下面的函数
Public Function Export_Excel(ByVal dgv As DataGridView) As Boolean
Try
If dgv.Rows.Count <= 0 Then '如果没有记录就退出
MessageBox.Show("没有记录可以导出", "没有可以导出的项目", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return False
End If
Dim ExcelAppliaction As Object
Dim Workbook As Object
ExcelAppliaction = CreateObject("Excel.Application")
Workbook = ExcelAppliaction.workbooks.add()
'For tt = 1 To 30 '30列都是文本格式------这里根据需要是否启用
' Workbook.worksheets(1).Columns(tt).NumberFormatLocal = "@"
'Next
Dim i As Integer = 0, row As Integer = 0, col As Integer = 0
For i = 1 To dgv.Columns.Count '在第三行开始显示表头
Workbook.worksheets(1).cells(3, i) = dgv.Columns(i - 1).HeaderCell.Value '这里的3表示从第3行开始
Next
Dim str(dgv.Rows.Count - 1, dgv.Columns.Count - 1) '定义一个二维数组---目的的快速导入(对于10万行以上效率惊人)
For row = 1 To dgv.Rows.Count '循环行
For col = 1 To dgv.Columns.Count '循环列
str(row - 1, col - 1) = dgv.Item(col - 1, row - 1).Value
Next
Next
Workbook.worksheets(1).range("A4").Resize(dgv.Rows.Count, dgv.Columns.Count).Value = str
Workbook.worksheets(1).Cells.EntireColumn.AutoFit() '自动列宽
ExcelAppliaction.visible = True '显示Excel
Workbook = Nothing
ExcelAppliaction = Nothing
Return True
Catch ex As Exception
MessageBox.Show(ex.Message, "出错了", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End Try
End Function