码迷,mamicode.com
首页 > 其他好文 > 详细

导出EXCEL

时间:2017-03-16 16:22:18      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:class   date   alt   color   attach   chm   str   tput   oar   

            DataSource.ResultData.ReportData = dv.ToTable();
            HSSFWorkbook hssfworkbook = Manager2.ExportExcel(DataSource, ReportTitleString);
            using (MemoryStream ms = new MemoryStream())
            {
                hssfworkbook.Write(ms);
                Response.Charset = "utf-8";
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
                Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(excelName, System.Text.Encoding.UTF8) + ".xls");
                Response.BinaryWrite(ms.ToArray());
                Response.End();
            }

 

  public ActionResult ExportToExcel()
        {
            NPOI.SS.UserModel.IWorkbook workbook = new NPOI.XSSF.UserModel.XSSFWorkbook();
            NPOI.SS.UserModel.ICell cell;
            NPOI.SS.UserModel.ISheet sheet = workbook.CreateSheet("StressTest");
            int i = 0;
            int rowLimit = 100;
            DateTime originalTime = DateTime.Now;
            for (i = 0; i < rowLimit; i++)
            {
                cell = sheet.CreateRow(i).CreateCell(0);
                cell.SetCellValue("值" + i.ToString());
            }

            using (MemoryStream ms = new MemoryStream())
            {
                workbook.Write(ms);
                var buffer = ms.GetBuffer();
                ms.Close();
                return File(buffer, "application/ms-excel", "test.xlsx");
            }
        }

<p><a  href="@Url.Action("ExportToExcel2")">导出Excel</a></p>

  来源:http://www.lanhusoft.com/Article/323.html

导出EXCEL

标签:class   date   alt   color   attach   chm   str   tput   oar   

原文地址:http://www.cnblogs.com/WJ--NET/p/6559225.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!