There are many possible solutions to this problem.
A. Use a Template Excel with the RequiredSheet Name with the first row contains data that matches your Datatype; like texts with more than 500 char long etc.
You keep this Excel with your solution and whenever you need to write to Excel, create a copy of this, insert records, and delete first
row.
B. Use Excel Object Model
C. Create Table in Excel using OLEDB driver using following statement
Create table [myTableName] (col1 int, col2 char(20))
Then insert to myTableName. myTableName is the SheetName you are creates.
Here you can also Drop Tables too...
if(conn.GetSchema("Tables", new String[]{null, null, "myTableName$", null}).Rows.Count != 0)
{
using ( OleDbCommand cmd = new OleDbCommand( "DROP TABLE [myTableName$]", conn ) )
cmd.ExecuteNonQuery();
}
I recommend the third option from my experience.
Thanks,
Kuthuparakkal