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
精彩评论