1
Answer

c# code to give Gridview cell name to exporting Excel file

Bineesh  VP

Bineesh VP

7y
228
1
Sir,
 
I am in winForm project in which I have to export datagridview data into excel sheet.
 
I have done almost except naming exported excel header columns to that of datagridview.
 
How can I set column headers to the exported excel file..help me
 
 
 
for (int i = 0; i < dgvBankAllocationReport.Rows.Count; i++)
{
for (int j = 0; j < dgvBankAllocationReport.Columns.Count; j++)
{
if (dgvBankAllocationReport.Rows[i].Cells[j].Value != null)
{
exceObj.Cells[i + 2, j + 1] = dgvBankAllocationReport.Rows[i].Cells[j].Value;
string colName = dgvBankAllocationReport.Columns[j].HeaderText;
}
}
}

Answers (1)