Quantcast
Viewing all articles
Browse latest Browse all 15749

Export Datagrid to Excel - MIssing First Row

Hi All

Pretty sure this is a simple correction but just can't spot it :( I am exporting from a datagrid into excel with the "insertion" code below. For some reason, It is missing the first row in the datagrid and copying everything else into excel... can someone please spot the school boy error I have made! I have played around with the I J K start values but to no avail.

Thank you in advance,,

Code:

        'Export the data from the datagrid to an excel spreadsheet
        For i = 0 To DataGridView1.RowCount - 1
            For j = 0 To DataGridView1.ColumnCount - 1
                For k As Integer = 1 To DataGridView1.Columns.Count

                    xlWorkSheet.Cells(1, k) = DataGridView1.Columns(k - 1).HeaderText
                    xlWorkSheet.Cells(i + 1, j + 1) = DataGridView1(j, i).Value
                Next
            Next
        Next


Viewing all articles
Browse latest Browse all 15749

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>