foreach (int i in arrRows)
{
for (int j = 0; j < CategoryGV.Columns.Count; j++)
{
worksheet.Cells[i + 2, j + 1] =
Convert.ToString(CategoryGV.Rows[i].Cells[j].Value);
}
}
The values in arrRows are the row index values from the data grid. So if you have flagged rows 3, 7, 8 and 12 those are the row numbers you will add to your worksheet. However since you use those values to address the worksheet, rows 1,2,4,5,6,9,10 and 11 will be blank. You need to use a proper sequential index counter to address the rows where you store the values from the datagrid.