How to save data from datagridview to excel file (* .xls)?

Dim book As Microsoft.Office.Interop.Excel.Workbook Dim sheet As Microsoft.Office.Interop.Excel.Worksheet book = book.Worksheets.Add(1) For i = 0 To 6 Step 1 For j = 0 To time sheet.Cells(i, j) = DataGridView1(i, j).Value Next j Next i sheet.SaveAs("c:\1.xls") book.Close() 
  • Dim book As Microsoft.Office.Interop.Excel.Workbook Dim sheet As Microsoft.Office.Interop.Excel.Worksheet book = book.Worksheets.Add (1) For i = 0 To 6 Step 1 For j = 0 To time sheet. Cells (i, j) = DataGridView1 (i, j). Value Next j Next i sheet.SaveAs ("c: \ 1.xls") book.Close () - yost
  • why does not it work? - yost

1 answer 1

Use third-party libraries, for example EPPlus . But the file will be *.xlsx