导出EXCEL

Posted WangJunZzz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了导出EXCEL相关的知识,希望对你有一定的参考价值。

            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的主要内容,如果未能解决你的问题,请参考以下文章

hutool工具导出excel代码示例

hutool工具导出excel代码示例

jsp导入和导出excel的代码(jsp连接excel的方法)

java五行代码导出Excel

急求php导出生成excel的代码

如何用java导入Excel数据到数据库?