ASP.NET:第三方插件,用于将数据从GridView导出到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版本。 现在,我正在拼命寻找其他方法,即使这意味着要使用第三方插件。只要它是免费的,并且可以在公司网站中使用。     

解决方法

使用:LumenWorks.Framework.IO.Csv http://www.codeproject.com/KB/database/CsvReader.aspx     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...