plz look this :
in Add Reference tab .NET
add :
Microsoft.Offilce.Interop.Excel
and in using add :
using Word = Microsoft.Office.Interop.Word;
using Excel = Microsoft.Office.Interop.Excel;
try
{
var xl = new Excel.Application();
xl.Workbooks.Add();
xl.DefaultSheetDirection = (int)Excel.Constants.xlRTL;
xl.Visible = true;
xl.Cells[1, 1] = "cell1";
xl.Cells[1, 2] = "cell2";
xl.Cells[1, 3] = "cell3";
for (int i = 0; i < dataGridView1.Rows.Count; i++)
for (int j = 0; j < 3; j++)
{
xl.Cells[i + 2, j + 1] = cl.clearSpase(dataGridView1.Rows[i].Cells[j].Value.ToString());
}
}
catch (Exception ex)
{
}