开发者

ASP.NET: 3rd party plugins to export data from GridView to Excel

开发者 https://www.devze.com 2023-03-08 16:50 出处:网络
Been using this method to export an excel file: HttpContext.Current.Response.Clear(); HttpContext.Current.Response.AddHeader(\"content-disposition\", string.Format(\"attachment; filename={0}\", \"Sin

Been using this method to export an excel file:

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();
    }
}

But there's a huge limitation with this method, Excel displays this warning every time I open the Excel file:

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?

The second method suggested to me was using Interop, but there were also some limitations:

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

One of which is that all the client's computers should have the same Excel version.

Now I'm desperately looking for other methods even if it means using a thir开发者_开发问答d party plugin. As long as it's free and can be used in a company website.


Use: LumenWorks.Framework.IO.Csv

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

0

精彩评论

暂无评论...
验证码 换一张
取 消