2016-08-02 2 views
-2
public ActionResult ExportToExcel() 
    { 
     GridView gv = new GridView(); 
     gv.DataSource = db.Details.Select(x => new 
     { 
      x.Title, 
      Category = x.Category.Title, 
      SubCategory = x.SubCategory.Title, 
      x.Count, 
      x.Price, 
      Automobiles = x.Automobiles.Count, 
      x.Description 
     }).ToList(); 
     gv.DataBind(); 
     Response.ClearContent(); 
     Response.Buffer = true;    
     Response.AddHeader("content-disposition", "attachment; filename=Marklist.xls"); 
     Response.ContentType = "application/ms-excel"; 
     Response.Charset = ""; 
     StringWriter sw = new StringWriter(); 
     HtmlTextWriter htw = new HtmlTextWriter(sw); 
     gv.RenderControl(htw); 
     Response.Output.Write(sw.ToString()); 
     Response.Flush(); 
     Response.End(); 
     return Json(true); 
    } 

내보내기가 로컬에서 올바르게 작동합니다. Azure에서는 작동하지 않습니다. 빈 파일 다운로드. 무슨 문제가 있다고 말해?Xls 내보내기가 서버에서 실행되지 않음

+0

우연히 COM을 사용합니까? – evilSnobu

+0

또한 로컬로 작동하려면 Excel이 설치되어 있어야합니까? – evilSnobu

+0

@evilSnobu 아니, 분명히 COM 또는 Excel Interop을 사용하지 않습니다. – mason

답변