Save to XPS - Outputstream

Hi,

I'm trying to save Excel files to XPS format, and I get an error when saving this to an Outputstream. With Aspose.Words and Aspose.PDF it works, but not with Aspose.Cells.Sample code:

Dim OutFile As New System.IO.FileInfo(Downloadlocatie)
If (OutFile.Extension = ".doc") Or (OutFile.Extension = ".docx") Then
   	Dim OutputDoc As New Aspose.Words.Document(Downloadlocatie)
	OutputDoc.Save(Context.Response.OutputStream, Aspose.Words.SaveFormat.Xps)
ElseIf (OutFile.Extension = ".pdf") Then
	Dim OutputDoc As New Aspose.Pdf.Document(Downloadlocatie)
	OutputDoc.Save(Context.Response.OutputStream, Aspose.Pdf.SaveFormat.Xps)
ElseIf (OutFile.Extension = ".xls") Or (OutFile.Extension = ".xlsx") Then
	Dim OutputDoc As New Aspose.Cells.Workbook(Downloadlocatie)
	'OutputDoc.Save("c:\www\file.xps", Aspose.Cells.SaveFormat.XPS)
	OutputDoc.Save(Context.Response.OutputStream, Aspose.Cells.SaveFormat.XPS)
End If

The code with extensions .doc / .docx / .pdf works perfectly. The code with .xls and .xlsx gives the following error. The outcommented part does work though!

The error I get:

De method is not supported
bij System.Web.HttpResponseStream.set_Position(Int64 value)
bij .Š.(Stream , ImageOrPrintOptions )
bij Aspose.Cells.Workbook.Save(Stream stream, SaveOptions saveOptions)
bij System.Web.UI.Control.LoadRecursive()
bij System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)De opgegeven methode wordt niet ondersteund.
bij System.Web.HttpResponseStream.set_Position(Int64 value)
bij .Š.(Stream , ImageOrPrintOptions )
bij Aspose.Cells.Workbook.Save(Stream stream, SaveOptions saveOptions)
bij System.Web.UI.Control.LoadRecursive()
bij System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

What can be wrong, is this a bug? Or should I change my code?

Kind regards,
Martin de Ruiter

Hi,


Please download and try the latest fix: Aspose.Cells for NET v7.2.0.2

If you still find the issue, kindly attach your template Excel file here, we will check it soon.

Thank you.

Hi,

I also tested it with that latest release you mentioned, but the same problem exists. I get this error with every excel document, see attached an example which also gives the error.

Kind regards,
Martin de Ruiter

Hi,

Please see this document how to convert your Ms-Excel document into XPS

Converting to XPS

Hi,


Well, it still works fine saving the XPS to output streams, see the sample code below and find attached the output XPS file that is generated from the streams here.

Sample code:

var workbook = new Aspose.Cells.Workbook(@“e:\test2\Test.xlsx”);
MemoryStream outputStream = new MemoryStream();
outputStream.Seek(0, SeekOrigin.Begin);
workbook.Save(outputStream, SaveFormat.XPS);

byte[] outs = outputStream.ToArray();

File.WriteAllBytes(“e:\test2\OutTestOut.xPS”, outs);

Well what you are showing is different, I'm trying to save to an ASP.NET response outputstream, I know saving to a file is working fine, the bug seems to be when saving to the context.response.outputstream:

OutputDoc.Save(Context.Response.OutputStream, Aspose.Cells.SaveFormat.XPS)

Can you explain why above code (see also my original message) is working with the Aspose Words and PDF components, but not with the Aspose.Cells?

Hi,


In a web application/project, if you need to use Response object to streaming the XPS format, you may use the relevant Workbook.Save() overloaded method accordingly, see the sample code below:

Workbook workbook = new Aspose.Cells.Workbook(@“e:\test2\TestOut.xlsx”);
workbook.Save(HttpContext.Current.Response, “test.xps”, Aspose.Cells.ContentDisposition.Attachment, new XpsSaveOptions(SaveFormat.XPS));
HttpContext.Current.Response.End();


There is no overloads that support to just save directly into Response.OutputStream object

Thank you.