2013-10-10 51 views
0

我正在使用c#.net的Excel導出工作。我正在使用下面的代碼,它在桌面和筆記本電腦中工作正常。導出Excel無法在IPAD中工作

homeServices = new HomeServices(); 
    string htmlOutput = ""; 
    HttpContext.Current.Response.Clear(); 
    HttpContext.Current.Response.ClearContent(); 
    HttpContext.Current.Response.ClearHeaders(); 
    HttpContext.Current.Response.Buffer = true; 
    HttpContext.Current.Response.ContentType = "application/ms-excel"; 
    HttpContext.Current.Response.Write(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">"); 
    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=Export.xls"); 
    HttpContext.Current.Response.Charset = "utf-8"; 
    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250"); 

    htmlOutput = homeServices.ExportHomeData(); 
    HttpContext.Current.Response.Write(htmlOutput); 
    HttpContext.Current.Response.Flush(); 
    HttpContext.Current.Response.End(); 

但是,當我在iPad上使用這個,我得到的錯誤,如

Unable to Read Document. An error occurred while reading the document. 

上面的代碼是否不會支持IPAD。

注:我已經搜查了很多,我不力找到至少針對此問題的相關解決方案。在過去的3天裏,我在尋找......真的幫助專家。

回答

0

上述代碼將在PC中產生輸出,但是,一種格式警告同樣會導致IPad中的問題。

您可以使用CSV代替Excel中,你不會得到錯誤,但仍然會在Excel中打開。

HttpContext.Current.Response.AppendHeader( 「內容類型」, 「應用/ CSV」); HttpContext.Current.Response.AppendHeader(「Content-disposition」,「attachment; filename =」+ fileName +「.CSV」);

相關問題