Thanks for the reply 
@Praveen : It is not working as per my requirement. Its seems like it is using Office XML Formats. Excel 2003 Viewer displaying it as a "Invalid File format" And 2007, I am getting some warning.
More on Wikipedia : http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats
@Sreejumon :I am not doing Office automation. Excel is not installed on my machine.
And I found one solution, but I am not sure it is good or not
I just created a Template XLS file with all the columns. And I am copying it and I am modifing the file using the following code.
using (OleDbConnection connection = new
OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + fileName + "; Extended Properties=Excel 8.0;"))
{
connection.Open();
string query = "INSERT INTO [Sheet1$] (Column1, Column2, Column3, Column4, Column5) VALUES(@Column1, @Column2, @Column3, @Column4, @Column5)";
using (OleDbCommand command = new OleDbCommand(query, connection))
{
foreach (DataRow item in this.dt.Rows)
{
command.Parameters.AddWithValue("@Column1", item["Column1"].ToString());
command.Parameters.AddWithValue("@Column2", item["Column2"].ToString());
command.Parameters.AddWithValue("@Column3", item["Column3"].ToString());
command.Parameters.AddWithValue("@Column4", item["Column4"].ToString());
command.Parameters.AddWithValue("@Column5", item["Column5"].ToString());
command.ExecuteNonQuery();
}
}
connection.Close();
}
Now it works fine. But only problem, the columns should be pre-defined.
Thanks
Anuraj P
http://www.dotnetthoughts.net
THIS POSTING IS PROVIDED "AS IS" WITH NO WARRANTIES, AND CONFERS NO RIGHTS.
BEWARE OF BUGS IN THE ABOVE CODE; I HAVE ONLY PROVED IT CORRECT, NOT TRIED IT.