Download Cells file

Hi all,

I want to open my Cells file which was saved by using this :

_response.setContentType(“application/vnd.ms-excel”);
_response.setHeader(“Content-Disposition”,“attachment; filename=“file”.xls”);

But it doesn’t work even if my cells file was succefully saved.
Thanks in advance

Hi,

We have forwarded your question to our development team. They will help you as soon as possible.

Hi,

Please try this code and see if it works fine. If you still encounter any problem, feel free to post again.

Java


String file = accBusinessController.getXlsFile(market,recty); // here I saved my file in a special directory

workbook.open(file);


ServletOutputStream outs = response .getOutputStream();


response.setContentType(“application/vnd.ms-excel”);

response.setHeader(“Content-Disposition”, “attachment; filename=sampleName.xls”);

workbook.save(outs);

outs.close();

Hi mshakeel.faiz,



Hi,

Thanks for your code example.

Actually, your issue is not related to Aspose.Cells, but it is related to JSP. You had already saved the excel file successfully by Aspose.Cells. You should search the answer in JSP and related output stream/writer.

Previously, you were just sending the file name to client and not the file content. You should first search for a code that will just send a simple file content to the client. For that purpose you can create Excel file manually too using MS-Excel. Once you are able to send file content to client, then embed your Aspose.Cells code inside it.

Thanks, I will change my code.

Hi mshakeel.faiz,

Since last time, I haven’t time to change my code. I will do today.
If I really understant what you suggest to me, I must do the same code to the client.
That is I must create a new worbook which contains the same worsheet, cells,…, that I had created in my DAO for my JSP?

Because, if I can open my file in my client service after saving it without create a file I will not need to use a download.

Thanks for your answer.


Hi,

If you want to send the xls file content to client, you must write the excel file data to the OutputStream that got by response.getOutputStream(). You have two choices to send the file data to this output stream:
1. Save the workbook to the output stream directly, just like the code in this post. In this way you need not create one xls file at your server side.
2. Save the workbook at your server side first(save to disk, or save in memory by a ByteArrayOutputStream), then get the saved file data and send it to the output stream to client. If you need to create the xls file at your server side for other purpose, this way is better because it avoids to save the workbook again. Also in this way you can separate the issue of Aspose.Cells or your JSP logic of sending data to client. If the file created by workbook.save() cannot be opened fine, it should be issue of Aspose.Cells. If the saved file can work fine at your server but cannot at the client, then the issue should be related with your JSP code of sending the file content(binary data) to client.
Thank you.

thanks babar.raza

I modified my code and I use this below but it doesn’t work. Even the dialog windows is not opened when I clicked on Run.

thanks

Hi,

It seems you failed to send an existing file to client even without any reference to Aspose.Cells. I am afraid the issue is related with your JSP/Servlet logic of request and response. At first you should check whether you have send the correct request from the client so that the code you given has been executed.
Thank you.

Hi,

No one can resolve this point with me?
I tried many solutions but impossible even to open this file without download.
I changed my release and I checked the directory where I saved my file and all is Ok, but I don’t have the dialog box, and any errors.

Is it really possible to have dialog box with Aspose?

Thanks

Hi,

Firstly I think you need to make your code work fine for downloading an existing file(without any reference to aspose.cells). And I am afraid your current code is invalid too when it be executed. From your code I think the file content has been sent to client twice in one same stream. Even the client can get the dialog and save the file, the file will be corrupted because of the duplicated data. I think you can remove the code using Aspose.Cells and then check whether you can get the file downloaded.

In fact I suspect that your code has never been executed so that you cannot get the dialog from client side. The most simple method to check it is that you add some log message such as System.out.println(…) in your code, if you cannot see those messages from your server, then there must have some problems in your code of processing client request.


Hi all,

I just want to thank you about all your proposal, now it’s working well.

Regards

Hi,


We are glad your problem is solved.

Regards,

I need to use print writer instead of Servletoutputstream. how can i write work book content to print writer

Hi,

Thanks for using Aspose.Cells.

Well, this question does not seem to be related to Aspose.Cells but it is related to print writer class library.

If you can write any file (stream or its bytes) in print writer, then you can also write Aspose.Cells workbook object.

So, please search on the internet how to write any file in print writer. Once, you know how to achieve it, you can then save the workbook object into stream or bytes and write inside print writer too.