Why showing error message while opening .xls file

前端 未结 6 1481
自闭症患者
自闭症患者 2020-12-30 09:14

In my asp.net, C# application we are generating and downloading .xls file. But when I\'m trying to open, it\'s giving a message

\"The file you are try

6条回答
  •  醉酒成梦
    2020-12-30 09:53

    Do you completely create the xls file or do you copy and fill a template xls file ? An incorrect format template file may cause the problem.

    Also, what provider do you use to fill your file ? - Microsoft.ACE.OLEDB.12.0 for xlsx/xlsm ? - Microsoft.Jet.OLEDB.4.0 for xls ?

    An incorrect provider/extension combination may cause the problem.

    According to your comment, here is a part of code where I have done that in the past : ( commented some of the lines as I don't remember why they where useful )

    Response.Clear();                           
    Response.ContentType = "application/vnd.ms-excel";
    //Response.ContentEncoding = Encoding.Default; 
    //Response.Charset=""; 
    Response.AddHeader("Content-Disposition: ",
        String.Format(@"attachment; filename={0}",myfileName));
    
    //EnableViewState = false; 
    
    Response.Write(myFileContentAsString); 
    Response.Flush();
    Response.Close();
    

提交回复
热议问题