How do I send a workbook to the user from an ajax call?
Hi,
Thanks for your posting and using Aspose.Cells for GridWeb.
Please download and use the latest version: Aspose.Cells
for GridWeb v2.7.7.2002 and let us know your feedback.
If your problem still occurs, please provide us a sample runnable project replicating this problem of sending workbook from ajax call alongwith the source xls/xlsx file being used by you.
Please also provide the screenshot to elaborate this issue more, it will help us investigate this issue.
Thanks for the quick reply.
dataTable , true, “A1”);
Hi,
Thanks for your sample code.
Your code looks fine to me except that you are not ending the response stream, so please change your code into this and see if it fixes your problem. Your code will looks like the following
workbook.Save(context.Response, fileName + “.xls”,Aspose.Cells.ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
HttpContext.Current.Response.End();
return null ;
Another thing is that you could try is ContentDisposition.Inline instead of ContentDisposition.Attachment.
a) Please call Response.End after calling workbook.Save method:
C#
wb.Save(this.Response, “AlertSummary.xls”, Aspose.Cells.ContentDisposition.Inline, new Aspose.Cells.XlsSaveOptions(Aspose.Cells.SaveFormat.Excel97To2003));
Response.End();
b) If Response.End() still does not workbook, please save the workbook to stream, then export it by Response, see the following code:
C#
wb.Save(ms, new Aspose.Cells.XlsSaveOptions(Aspose.Cells.SaveFormat.Excel97To2003)); ;
this.Response.ContentType = “application/vnd.ms-excel”;
Response.AddHeader(“content-disposition”, “inline; filename=AlertSummary.xls”);
Response.BinaryWrite(ms.ToArray());
Response.End();
Hi,
I am having the exact same issue, but using Java. I was hoping you could help me.
My code looks like this:
String contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
resp.setContentType(contentType);
resp.addHeader("content-disposition", "attachment;filename="+fileName);
workbook.save(resp.getOutputStream(), SaveFormat.XLSX);String contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
resp.setContentType(contentType);
resp.addHeader("content-disposition", "attachment;filename="+fileName);
workbook.save(resp.getOutputStream(), SaveFormat.XLSX);
If I go to this routine using a form submit it works fine, but when I use a JSON post, the workbook gets filled up fine but won't call the "save or open" dialog box on the page.
Thanks,
Brita
Hi Brita,
Thanks for your posting and using Aspose.Cells for Java.
Your code looks fine and there seems to be no problem. However, you can try inline instead of attachment.
So, please change the following line
resp.addHeader(“content-disposition”, “attachment;filename=”+fileName);
into this line
resp.addHeader(“content-disposition”, “inline;filename=”+fileName);
and see how things go at your end.