You're experiencing one-off errors because of the fact that ExcelApp.Cells isn't zero based and you have a header row.
To combat this you can use foreach and separate out your header export to a separate block. It does take a little bit more code but I find it easier to deal with and less error prone
int i = 1;
int j = 1;
//header row
foreach(DataColumn col in dtMainSQLData.Columns)
{
ExcelApp.Cells[i, j] = col.ColumnName;
j++;
}
i++;
//data rows
foreach(DataRow row in dtMainSQLData.Rows)
{
for (int k = 1; k < dtMainSQLData.Columns.Count + 1; k++)
{
ExcelApp.Cells[i, k] = row[k-1].ToString();
}
i++;
}