We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Why i don't export excel file with template in devexpress mvc

Hi Teams,

I don’t know the reason i don’t export to excel file.

This is code in my class

WorkbookDesigner wbdesigner;
try
{
wbdesigner = new WorkbookDesigner();
wbdesigner.Open(path);
wbdesigner.ClearDataSource();

foreach (DataTable item in objTable)
{
wbdesigner.SetDataSource(item);
}
wbdesigner.Process();

//save workbook
wbdesigner.Workbook.Save(HttpContext.Current.Response, SaveFormat.Excel97To2003, ContentDisposition.Inline);
}
catch
{
}

This is code in controller


ExportReport export = new ExportReport();
DataTable Detail = new DataTable();

var data = db.PO_REQUESTDETAIL.Where(n => n.DocEntry == docEntry).ToList();

Detail = Global.ConvertToDataTable(data);

DataTable dtRpt1 = new DataTable();

dtRpt1 = Detail;
dtRpt1.TableName = "Detail";
DataTable[] arrTable = { dtRpt1 };

export.Export2Excel(Server.MapPath("~/RptTemplate/rptPO_RequestDetail.xls"), arrTable, "rptPO_RequestDetail.xls");

Hi,

Thanks for providing us sample code and details.

Well, Workbook object can be saved to memory stream (please browse different overloads of Save() method for your reference). From memory stream, you can get bytes (array) and output to the client browser from your MVC application. So, you should be able to resolve your issue.
Please check the following thread for your reference:
Using Save with Asp.net MVC

If you still find the issue, please share with us your simplest MVC application (you may zip the VS.NET solution prior attaching here) which we could run at our end and replicate the issue, we will check it soon.

Thank you.

Hi Amjad Sahi,

My work , i want export file with my template which i design on available like the file attachment. I using the above code i sent. But i’m fail.

Do you know the reason or the solution for my issue ?

Thank you for reading my post, Amjad Sahi,

Hi,

Thanks for the template file.

quocdang:

My work , i want export file with my template which i design on available like the file attachment. I using the above code i sent. But i'm fail.

Well, in my previous reply, I suggested you to choose the relevant overload to save the Workbook to memory stream instead and then output to the client browser accordingly (see the complete thread for your reference but it looks like you are still using your original code). Please update your code accordingly and it should work fine.

If you still find the issue, kindly do create a simple VS.NET project (runnable), zip it and post us here to reproduce the issue on our end, we will check it soon.

Thank you.