Aug 08, 2013, 4:18 AM
[CLOSED] How can i download Excel file from the server side with Ext.Net with C#
Hi all,
My case is, I try to generate my report with an excel file by getting information from my database and then write it into the excel file and after that i need to download that excel file into client machine but this kind of code work properly when it use ASP.Net only. When i try it with Ext.Net it doesn't work. Any help about this would be appreciate and thank in advanced because i'm stucking with this now....
Here is my code:
My case is, I try to generate my report with an excel file by getting information from my database and then write it into the excel file and after that i need to download that excel file into client machine but this kind of code work properly when it use ASP.Net only. When i try it with Ext.Net it doesn't work. Any help about this would be appreciate and thank in advanced because i'm stucking with this now....
Here is my code:
protected void SaveYearPDFClick(object sender,EventArgs e)
{
Microsoft.Office.Interop.Excel.Application appExl;
Microsoft.Office.Interop.Excel.Workbook workbook;
Microsoft.Office.Interop.Excel.Worksheet NwSheet;
appExl = new Microsoft.Office.Interop.Excel.ApplicationClass();
//Opening Excel file(myData.xlsx)
workbook = appExl.Workbooks.Open(Server.MapPath(@"~/Reports/CertifyTemplate.xlsx"), Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
NwSheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets.get_Item(1);
StudentCertify myStudent = StudentPB_CADB.GetCertifyInformation();
NwSheet.Cells[12, 3] = myStudent.FullName.ToString();
NwSheet.Cells[12, 14] = myStudent.FullNameLatin.ToString();
NwSheet.Cells[14, 2] = myStudent.SexName.ToString();
NwSheet.Cells[14, 5] = myStudent.Identity.ToString();
NwSheet.Cells[14, 9] = myStudent.NationalityName.ToString();
NwSheet.Cells[14, 12] = myStudent.SexNameLatin.ToString();
NwSheet.Cells[14, 15] = myStudent.Identity.ToString();
NwSheet.Cells[14, 20] = myStudent.NationalityNameLatin.ToString();
NwSheet.Cells[16, 4] = myStudent.DateBirth.ToString();
NwSheet.Cells[16, 14] = myStudent.DateBirthLatin.ToShortDateString();
NwSheet.Range["N16"].NumberFormat = "dd/mm/yyyy";
workbook.Save();
workbook.Close();
appExl.Quit();
try
{
string XlsPath = Server.MapPath(@"~/Reports/CertifyTemplate.xlsx");
FileInfo fileDet = new System.IO.FileInfo(XlsPath);
Response.Clear();
Response.Charset = "UTF-8";
Response.ContentEncoding = Encoding.UTF8;
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fileDet.Name));
Response.AddHeader("Content-Length", fileDet.Length.ToString());
Response.ContentType = "application/ms-excel";
Response.WriteFile(fileDet.FullName);
Response.End();
}
catch (Exception ex)
{
throw ex;
}
}
Last edited by Baidaly; Aug 09, 2013 at 2:30 AM.
Reason: [CLOSED]