I have Tried a code to export datagridview data to excl file, it is working perfectly but
it actually just exports it to an existing excel file. is it possible to have a code that can create a new excel file.
i have tried the code below please check
What I have tried:
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
Dim i As Integer
Dim j As Integer
xlApp = New Microsoft.Office.Interop.Excel.Application
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets("sheet1")
For i = 0 To TAPDataGridView.RowCount - 2
For j = 0 To TAPDataGridView.ColumnCount - 1
For k As Integer = 1 To TAPDataGridView.Columns.Count
xlWorkSheet.Cells(1, k) = TAPDataGridView.Columns(k - 1).HeaderText
xlWorkSheet.Cells(i + 2, j + 1) = TAPDataGridView(j, i).Value.ToString()
Next
Next
Next
xlWorkSheet.SaveAs("C:\Users\P A R\Documents\?.xlsx")
xlWorkBook.Close()
xlApp.Quit()
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
MsgBox("You can find the file D:\Todays_record_excel.xlsx")
End Sub