Free Support Forum -

"Cannot find central directory" exception when opening workbook from a stream

I am using Aspose.Cells version

I am trying to open an Excel sheet stored in the database. When I execute the code below I get the "Cannot find central directory".

DataSet ds = new DataSet("MyFiles");

byte[] MyData = new byte[0];

da.Fill(ds, "MyFiles");

DataRow myRow;

myRow = ds.Tables["MyFiles"].Rows[0];

MyData = (byte[])myRow["FileData"];

int ArraySize = new int();

ArraySize = MyData.GetUpperBound(0);

stream.Write(MyData, 0, MyData.GetUpperBound(0));

stream.Seek(0, SeekOrigin.Begin);

Aspose.Cells.Workbook wkbk = new Aspose.Cells.Workbook(stream);

Please let me know what I am doing wrong....


It looks you might embedded Excel OLE-object in MS Access or so. If this is the case, I am afraid, Aspose.Cells cannot extract OLE-objects from MS Access, it will work if the embedded object is in Excel file. If you got separate Excel file and you got issue opening the file via stream by Aspose.Cells, please attach the Excel file to show the issue. And, we can test your issue by opening/loading the file via streams using Aspose.Cells for .NET API.

Thank you.

I am save the excel file and not OLE objects to the datbase. I ahve attached the file. Please test it and let me know. If it works, please send me your code so I can try it as well…


Thanks for sharing the Excel file.

I used the following two code segments to load/open the file, it works fine.

System.IO.FileStream fstream = new System.IO.FileStream("e:\\test2\\userexcel.xlsx", FileMode.Open);
LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);
Workbook workbook = new Workbook(fstream, loadOptions);

FileStream fs = File.Open(@"e:\test2\userexcel.xlsx", FileMode.Open);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
MemoryStream ms = new MemoryStream(buffer);
LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);
Workbook workbook = new Workbook(ms, loadOptions);

I used our latest version/fix v7.0.1.1: Please try the latest version/fix v7.0.1.1

Thank you.