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

Free Support Forum - aspose.com

What is the default format for workbook

Hello,

We are creating a workbook in memory passing the file format type Xlsx in the constructor, than write to a worksheet then upload the workbook to our database as binary without saving it to the filesystem. During our process we download the binary from the database and upload it to SharePoint 2010 with a .xlsx extension without saving it to the filesystem. When we open the workbook from the SharePoint site excel throws an error saying that the format or the extension is incorrect. When we upload the workbook to SharePoint with an .xls extension it works fine. Is there anyway to have the workbook created with the xlsx format?

Hi,

Thanks for your posting and using the Aspose.Cells for .NET.

I have written the following code to illustrate how to save the worbook in xlsx format inside a stream and get it bytes.

The code is fully commented and will give you a whole idea.

I have also attached the output file generated by the code.

C#


//Create a workbook object

Workbook workbook = new Workbook();


//Create a memory stream

MemoryStream ms = new MemoryStream();

ms.Position = 0;


//Save the worbook into memory stream in xlsx format

workbook.Save(ms, SaveFormat.Xlsx);


//The below code is for testing only


//Now read bytes from stream and save it in file with xlsx extension

byte[] bytes = new byte[ms.Length];

ms.Read(bytes, 0,bytes.Length);


///Output.xlsx will open fine

System.IO.File.WriteAllBytes(@“F:\Shak-Data-RW\Downloads\Output.xlsx”, bytes);



What is the workbook constructor that takes a file format used for if not to set the format of the workbook?

If I'm reading your code correctly, for my scenario, I would have to take these steps

1. download the byte array from database

2. write the byte array to a memory stream

3. create a new workbook from the memory stream

4. save the workbook to a memory stream with the xlsx format enumeration

5. convert the memory stream back to an array

6. upload byte array with correct format to the SharePoint site.

or modify all the places that are uploading a workbook and do steps 4 and 5 before the book is uploaded to the database.

Is that correct?

Hi,


"What is the workbook constructor that takes a file format used for if not to set the format of the workbook?"
Well, if you are instantiating a new blank Workbook from the scratch, then you may create the workbook for XLSX file format by using its constructor (e.g Workbook wb = new Workbook(FileFormatType.Xlsx)). But, if you are creating a workbook from the stream, it will not help much.

Also, I would suggest to check the following documents for reference:
http://docs.aspose.com/display/cellsnet/Opening+Files
http://docs.aspose.com/display/cellsnet/Saving+Files

I think your pointed steps look fine to me.

Thank you.

Hi,

Yes, the steps mentioned by you are correct.

Also, you can change your format by changing the format enumeration.