Aspose.Cells.Excel object in a web service

If I develop a .NET web service which creates an Aspose.Cells.Excel object, how can I pass it back to a Web application client and have the client app display it in the browser? Can I serialize an Aspose.Cells.Excel object, and can it be deserialized on the client side and displayed in the browser as regular Excel (not Aspose Excel) ?

Excel object is not serializable. You can save the file into a stream and serialize it.

Can I save the Excel file from memory to a stream without saving it on disk first ? I have not done this before. Can you show me a sample piece of code to do this ? I need to save it to a stream, serialize the stream and send it back to the client for deserialization, to be displayed in the browser.

Excel excel = new Excel();

// creates the output file here

........

//saves file to stream

MemoryStream stream = new MemoryStream();

excel.Save(stream);

//serialize and deserialize the stream to a new MemoryStream

......

//send the excel file to client and display file in the browser

byte[] data = newStream.ToArray();

this.Response.ContentType = "application/xls";
Response.AddHeader( "content-disposition","inline; filename=book1.xls");
Response.BinaryWrite(data1);
Response.End();

Thanks, this is very useful. However, I am having some problems in the following part of your response:

//serialize and deserialize the stream to a new MemoryStream

......

I am not sure if I should serialize the variable "stream" into another variable. Here is my code - any help is highly appreciated:

//**************************************************************************************

Serializer.SerializationFormat format = Serializer.SerializationFormat.Binary;

System.IO.MemoryStream objStream = new System.IO.MemoryStream();

objChartExcel.Save(objStream, FileFormatType.Default);

System.IO.MemoryStream objSerializedStream = Serializer.Serialize(objStream, format);

Object obj2 = new System.IO.MemoryStream();

Aspose.Cells.Excel objExcel2 = new Aspose.Cells.Excel();

obj2 = Serializer.DeSerialize(objSerializedStream, format);

System.IO.MemoryStream objDeserializedStream = (System.IO.MemoryStream)obj2;

byte[] data1 = objSerializedStream.ToArray();

this.Response.ContentType = "application/xls";

Response.AddHeader( "content-disposition","inline; filename=US_Product_Watch_Weekly_Share.xls");

Response.BinaryWrite(data1);

Response.End();

//***********************************************************************************************

Laurence, I think I figured it out. It seems to be working now.

Using one of the overloads of the Excel.Save method, can I send a Response object back to the client application? Do I need to serialize/deserialize/stream anything for that?

What is the best way to do this if the chart is created by a .NET Web service and the client that needs to display the Excel is a J2EE browser application?

1. You don't need to send the Response object. Just use the Response object in the web application.

2. As I know, other browser cannot display Excel file in it. They generally prompt to save the file or lauch MS Excel to display it.