You should do a check first to see if the row is visible first like this
for (int i = 0; i < dg1.Rows.Count - 1; i++)
{
if (dg1.Rows[i].Visible)
{
for (int j = 0; j < dg1.Columns.Count; j++)
{
worksheet.Cells[i + 2, j + 1] = dg1.Rows[i].Cells[j].Value.ToString();
}
}
}
Hope this helps