【问题标题】:ASP.NET: 3rd party plugins to export data from GridView to ExcelASP.NET:将数据从 GridView 导出到 Excel 的第 3 方插件
【发布时间】:2011-05-26 05:30:28
【问题描述】:

一直用这种方法导出excel文件:

HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Single_Raw.xls"));
        HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
using (StringWriter sw = new StringWriter())
{
    using (HtmlTextWriter htw = new HtmlTextWriter(sw))
    {
       // some code

        HttpContext.Current.Response.Write(sw.ToString());
        HttpContext.Current.Response.End();
    }
}

但是这种方法有一个很大的限制,每次我打开 Excel 文件时 Excel 都会显示这个警告:

The file you are trying to open < > is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?

向我建议的第二种方法是使用 Interop,但也有一些限制:

http://www.gemboxsoftware.com/LA/Excel-Automation-and-Excel-Interop.htm

其中之一是客户的所有计算机都应具有相同的 Excel 版本。

现在我正在拼命寻找其他方法,即使这意味着使用第三方插件。只要它是免费的并且可以在公司网站上使用。

【问题讨论】:

    标签: asp.net excel gridview export-to-excel


    【解决方案1】:

    使用:LumenWorks.Framework.IO.Csv

    http://www.codeproject.com/KB/database/CsvReader.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多