odlan yer odlan yer - 2 months ago 20
ASP.NET (C#) Question

export gridview to excel using closed xml with 1 column apart

I'm exporting gridview to excel using ClosedXML, I want my output to have a one column apart. Like this.
enter image description here

This is my code for the gridview header part.

for (col = 0; col < headerCount; col++)
{
worksheet.Cell(3, current + 1).Value = GridView1.HeaderRow.Cells[col].Text;

}


Note: My gridview column count is dynamic.

Answer

Try this:

for (col = 0; col < headerCount; col++)
{
    worksheet.Cell(3, current * 2 + 1).Value = GridView1.HeaderRow.Cells[col].Text;
}