We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Getting Error in the aspose code

hi

i got the following code from aspose team

MemoryStream ms = new MemoryStream();

ms.Write(bytes, 0, bytes.Length);
ms.Position = 0;
Workbook workbook = new Workbook(ms);
but when am using this code am getting an error "Cannot find central directory" in the following line
" Workbook workbook = new Workbook(ms);" please help to resolve this problem

Hi Ajeesh,

Please post your queries at Aspose.Cells forum which are related to MS Excel. Please put your question in the reply of Aspose.Cells team.

Hi,

Please check the complete running sample code below.

It reads the sample source file into byte array, you will read it from database. Then it creates a memory stream object and then workbook object and prints “Welcome Aspose!” in cell A1 and write the output xlsx file.

I have also attached the source and output xlsx files for your reference.

You can also see the screenshot attached by me.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;


//Read all bytes into a byte array

byte[] bytes = System.IO.File.ReadAllBytes(filePath);


//Create a memory stream

MemoryStream ms = new MemoryStream(bytes);

ms.Position = 0;


//Create a workbook object

Workbook workbook = new Workbook(ms);


//Do some work on workbook object of your choice, i will print Welcome Aspose in cell A1

workbook.Worksheets[0].Cells[“A1”].PutValue(“Welcome Aspose!”);


//Save the workbook

workbook.Save(filePath + “.out.xlsx”, SaveFormat.Xlsx);