We are building an application where in user will be able to export a list containing data using aspose.cells .NET.
What I have achieved so far is that, I have been able to get the data, transform, filter and write it physically to an excel file (thanks to easily consumable aspose libraries.
Our application’s design is as follows :
An XHR request hits the RESTful service (.NET WebAPI 2).
The service calls a business component which first gathers data from database and then passes it to a library that performs the job of transforming the data and filtering it.
The result data is then sent to another library which implements Strategy pattern as follows:
----An object is instantiated based on what type of export is expected viz. Excel or Pdf
----The result set is passed to an export method of the instantiated object that will generate excel or pdf and return a response.
What I need to do is :
I want the method that generates the excel and pdf file to return HttpResponseMessage that I can blindly return to the client and then the client can interpret the response type and download a file physically.
Also, to add, I tried certain ways to do it, my browser keeps giving me CORS error. I also tried adding allow-access-origin for content disposition to header, but no luck,
Please help! Any guidance will be greatly appreciated. I have lost my depth here.
Apparently this query does not seem to be related to Aspose.Cells as it does not provide any feature to convert the resultant Excel or PDF file to HttpResponseMessage. However if we google we can have lot of solutions as given below:
public HttpResponseMessage Generate()
Workbook wb = new Workbook(FileFormatType.Xlsx);
string[,] array = new string[,]
wb.Worksheets.Cells.ImportTwoDimensionArray(array, 0, 0);
MemoryStream stream = wb.SaveToStream();
var result = new HttpResponseMessage(HttpStatusCode.OK)
Content = new ByteArrayContent(stream.ToArray())
FileName = "output.xlsx"
I tried this approach. Unfortunately, it doesn’t fit my requirements.
Apologies, I should have been more clear. All I need is to download an excel or a pdf file without actually needing to write it physically. The implementation should follow the design mentioned in the topic.
You are seeing the text “Created with Aspose.Cells for .NET…” because of evaluation limitation as mentioned in below help topic.
Moreover, I am afraid these forums are specific to Aspose APIs, so we cannot help you much about manipulation of streams. Please browse the internet and you will certainly learn about your requirements. If you encounter the issue while saving the file to stream in your local environment, then share your sample application and we will investigate if Aspose.Cells API is causing the problem.
I debugged and wrote intermediate file on the server side and found that there was no problem with the file being generated.
It’s my client code that’s causing the problems.
I believe we can close this thread now.