ASP.NET:第三方插件,用于将数据从GridView导出到Excel

时间:2011-05-26 05:30:29

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

使用此方法导出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版本。

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

1 个答案:

答案 0 :(得分:0)

使用:LumenWorks.Framework.IO.Csv

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