title: DataGridView missing last row in the Excel file
body: <p>So when i try to export my data on datagridview to excel, the last row in the excel file was not included, and here i used datasource to connect the ms.access database. Can you guys help ?</p>
  <p>BtnPrint.Click</p>
  <pre><code>SaveFileDialog1.Filter = &quot;Excel Files (*.xlsx)|*.xlsx&quot;
  
      If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
          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(&quot;sheet1&quot;)
  
          For i = 0 To SKU2021DataGridView.RowCount - 2
              For j = 0 To SKU2021DataGridView.ColumnCount - 1
                  For k As Integer = 1 To SKU2021DataGridView.Columns.Count
                      xlworksheet.Cells(1, k) = SKU2021DataGridView.Columns(k - 1).HeaderText
                      xlworksheet.Cells(i + 2, j + 1) = SKU2021DataGridView(j, i).Value.ToString()
                  Next
              Next
          Next
          xlworksheet.SaveAs(SaveFileDialog1.FileName)
          xlworkbook.Close()
          xlapp.Quit()
  
          releaseobject(xlapp)
          releaseobject(xlworkbook)
          releaseobject(xlworksheet)
  
          MessageBox.Show(&quot;Proses Export Berhasil&quot;, &quot;Sukses&quot;, MessageBoxButtons.OK, MessageBoxIcon.Information)
      End If
  </code></pre>
  <p>ReleaseObject()</p>
  <pre><code>Private Sub releaseobject(ByVal obj As Object)
      Try
          System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
          obj = Nothing
      Catch ex As Exception
          obj = Nothing
      Finally
          GC.Collect()
      End Try
  End Sub
  </code></pre>
  <p><a href="https://i.stack.imgur.com/f2BCm.png" rel="nofollow noreferrer">Here The Pic of The Excel and WindowForm</a></p>