Bineesh  Viswanath

Bineesh Viswanath

  • NA
  • 1k
  • 777.7k

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

Feb 4 2017 7:25 AM
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)