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

Free Support Forum - aspose.com

Problem opening excel workbook


I am trying to save the excel workbook as an array of bytes and displaying it in the web browser as follows

Dim ms As New IO.MemoryStream

xls.Save(ms, FileFormatType.Excel2000)

Dim Bytes As Byte() = ms.GetBuffer()





Response.AddHeader("pragma", "no-cache")

Response.Buffer = True

Response.ContentType = "application/ms-excel"

Response.AppendHeader("content-disposition", "attachment; filename=Excelfile.xls")

Response.OutputStream.Write(Bytes, 0, Bytes.Length - 1)

The above code works most of the times, but sometimes it gives an error when opening the excel file. Pls see the attached file.

When the above code is changed as follows, it works fine.

Response.OutputStream.Write(Bytes, 0, Bytes.Length)

Can you pls tell us what the problem is, as to why the error is inconsistent?




Well, we think there is an error in your code segment.
If you use: Dim Bytes As Byte() = ms.GetBuffer() then you should be using Response.OutputStream.Write(Bytes, 0, ms.Length - 1)

If you use: Bytes As Byte() = ms.ToArray() then you should use Response.OutputStream.Write(Bytes, 0, Bytes.Length - 1)

Thank you.


I tried changing ms.GetBuffer to ms.ToArray and used the following.

Response.OutputStream.Write(Bytes, 0, Bytes.Length - 1)

But I still get the same error. Looks like it is something else.

It still works with "Response.OutputStream.Write(Bytes, 0, Bytes.Length)"

Any help is greatly appreciated.



Following is my code that works fine with the latest version v4.9.1.

// Save workbook to Memory
workbook.Save(ms, FileFormatType.Excel97To2003);

byte[] aBytes;

// Write all Data
aBytes = ms.ToArray();

// Send as file to browser…
Response.AppendHeader(“Content-Disposition”, "inline;filename = " + “MyFile.xls”);
Response.ContentType = “application/msexcel”;
Response.AddHeader(“content-length”, Convert.ToString(aBytes.Length));

// Free Stream

Thank you.

Hello. What is the significance of saving the file under the format type of Excel2000 versus Excel97To2003?


Well, nothing special about it as both formats (Excel2000 and Excel97To2003) are same. In the latest version of the product, we just deprecated the older file format types i.e. ., Excel97, Excel2000, ExcelXP, Excel2003 etc. and merged them into single format: Excel97To2003. For your information there is not much difference in Excel97 - Excel2003 format types or in their BIFF specifications.

Thank you.