您的位置:首页 > 其它

Npoi导入导出Execl

2015-07-16 10:48 92 查看
读取csv格式时内容含有逗号的无法处理

protected void downloadfile(DataTable dd, string s_path)
{

#region 下载服务器上生成的execl文件
System.IO.FileInfo file = new System.IO.FileInfo(s_path);
HttpContext.Current.Response.ContentType = "application/ms-download";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.WriteFile(file.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Clear();
//下载完成后删除服务器下生成的文件
if (File.Exists(s_path))
{
File.Delete(s_path);

}
HttpContext.Current.Response.End(); ;
#endregion

#region   将二进制字符串数组写入输出流

HttpContext.Current.Response.ContentType = "application/ms-download";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
HttpContext.Current.Response.Charset = "utf-8";

HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode("222.xls", Encoding.UTF8));//222.xls下载是默认文件名

HttpContext.Current.Response.BinaryWrite(ProductBLL.download.ExcelHelper.TableToExcel(dd,"xls").GetBuffer());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Clear();

HttpContext.Current.Response.End();
#endregion


web下载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: