OWC issue on Excel file generation

B

Bertrand Bram

Hi !

I currently have a problem with OWC library (v10.0.4505.0) in C# : my
program is trying to read an Excel file it generated before. The problem
is, the Excel file is written in XML format and the program doesn't seem
to be able to handle this ("External table is not in the expected format").

Writing section :
---------------
SpreadsheetClass xlsheet = new SpreadsheetClass();
xlsheet.ActiveSheet.Cells[1,1] = "Hello";
xlsheet.Export(xlFileName,
SheetExportActionEnum.ssExportActionNone,
SheetExportFormat.ssExportHTML);
Response.ContentType = "application/x-msexcel";
Response.AppendHeader("content-disposition",
"attachment; filename=\"" + xlFileName + "\"");
Response.WriteFile(fileName);

Reading section :
---------------
string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + xlFileName + ";" +
"Extended Properties=\"Excel 8.0;HDR=Yes\"";
OleDbConnection objConn = new OleDbConnection(sConnectionString);
objConn.Open(); // "External table is not in the expected format" when
trying

Can anyone solve this problem ? Thanks in advance !
 
A

Alvin Bruney

The excel object cannot read xl files. I know it sounds wierd but it is
mostly true. Well, it can be made to read xl if you really want it to but it
just isn't worth the hassle. One solution you can try is to modify your read
section to accept a csv file. Once you have the data, you can stream it as
excel, but save it as csv
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top