tags:

views:

18

answers:

1

I trying to copy the one excel sheet to another excel sheet. I have a excel file and in it there is a sheet. Now I want to create a new excel file which should have the another sheet with the data which is in the earlier sheet as well as some updated data also.

For this I am reading the whole data from first excel sheet and storing in some DataTable, which is working fine.

But now when I am creating a excel sheet through StreamWriter and trying to open that connection for inserting the records it is giving me this error.

"External table is not in the expected format in excel "

System.IO.StreamWriter oExcelWriter = System.IO.File.CreateText(@"filename.xls");

conn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=file.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=0"";";

why it is giving this error. I don't want to use Interop, I want to use OleDb only.

A: 

You can always use an empty excel file as a template and then instead of creating new file, make a copy of template and open it.

VinayC