excel导出自动保存。求助.
Dim MyExcel As New Microsoft.Office.Interop.Excel.Application()
MyExcel.Application.Workbooks.Add()
MyExcel.Visible = True
'获取标题
Dim Col As Integer
For Col = 1 To DataGridView1.Columns.Count
MyExcel.Cells(1, Col) = DataGridView1.Columns(Col - 1).HeaderText
Next
'往表格添加数据
Dim RowNum As Integer
For RowNum = 0 To DataGridView1.RowCount - 1
Dim ColNum As Integer
For ColNum = 0 To DataGridView1.ColumnCount - 1
If Me.DataGridView1(ColNum, RowNum).Value Is System.DBNull.Value Then
MyExcel.Cells(RowNum + 2, ColNum + 1) = ""
Else
MyExcel.Cells(RowNum + 2, ColNum + 1) = DataGridView1(ColNum, RowNum).Value
End If
Next
Next
MyExcel.Visible = false