epplus导出excel

            DataTable Log = DbHelperSQL.Query(" select * from WorkSummaryLog ").Tables[0];

    //查出数据库的数据放入DataTable表内
            ExcelWorksheet ws = pck.Workbook.Worksheets.Add("he");

    //为页码添加一个名字
            ws.Cells["a1"].LoadFromDataTable(Log, true);

    //导出从a1开始
            var data = pck.GetAsByteArray();

    //保存和归来的Excel文件作为一个ByteArray
            context.Response.Clear();  

    //输出头文件  
            context.Response.AddHeader("content-disposition", "attachment;  filename=日志记录.xlsx");
            context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            context.Response.BinaryWrite(data);
            context.Response.Flush();
            context.Response.End();

posted @ 2016-09-23 16:35  Jesh_95  阅读(634)  评论(1编辑  收藏  举报