0

我正在 c# .net 中的 Excel 导出中工作。我正在使用以下代码,该代码在台式机和笔记本电脑上运行良好。

   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 天里,我正在搜索..请帮助专家。

4

1 回答 1

0

上面的代码将在 PC 中产生输出,但是,有一种格式警告,同样在 iPad 中出现问题。

您可以使用 csv 代替 Excel,不会出错,但仍会在 excel 中打开。

HttpContext.Current.Response.AppendHeader("Content-Type","application/CSV"); HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment; filename=" + fileName + ".CSV");

于 2014-09-02T11:52:39.443 回答