Click here to Skip to main content
15,895,859 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i m trying this but nothing get Column name or header in excel


C#
for (i = 1; i < dataGridView2.Columns.Count + 1; i++)
            {

                xlWorkSheet.Cells[1, i] = dataGridView2.Columns[i - 1].Name;
            }

            for (i = 0; i <= dataGridView2.RowCount - 1; i++)
            {
                for (j = 0; j <= dataGridView2.ColumnCount - 1; j++)
                {
                    DataGridViewCell cell = dataGridView2[j, i];
                    xlWorkSheet.Cells[i + 1, j + 1] = cell.Value;
                }
            }



Aaqib
Posted

1 solution

Use a for loop and bind

C#
DataGridView2.Columns[i].HeaderText
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900