zoukankan      html  css  js  c++  java
  • repter导出到Excel

     public void DataReadAndWiteToExcel()
            {
                try
                {
                    BaseBLL bll = new BaseBLL();
                    #region 导出数据格式
                   // var list = bll.GetModelList<MSP_GroupUserVideo>("IsDelete=0", "MSP_GroupUserVideo");
                    var list = Bindrepter();
                    int rownum = 1;
                    //创建表头,填充表头
                    HSSFWorkbook workbook = new HSSFWorkbook();
                    ISheet sheet1 = workbook.CreateSheet("sheet1");

                    sheet1.SetColumnWidth(015 * 250);
                    sheet1.SetColumnWidth(115 * 250);
                    sheet1.SetColumnWidth(215 * 200);
                    sheet1.SetColumnWidth(315 * 300);
                    sheet1.SetColumnWidth(415 * 300); 

                    IRow row = sheet1.CreateRow(0);
                    row.CreateCell(0).SetCellValue("单位");
                    row.CreateCell(1).SetCellValue("登录ip");
                    row.CreateCell(2).SetCellValue("观看时间");
                    row.CreateCell(3).SetCellValue("视频");
                    row.CreateCell(4).SetCellValue("状态"); 
                    foreach (MSP_GroupUserVideo item in list)
                    {
                        string name = GetOther(item.GroupUserId, 1);//单位
                        string ip = GetOther(item.GroupUserId, 2);//IP
                        string StartTime = Convert.ToDateTime(item.StartTime).ToString("yyyy-MM-dd:HH:ss:ss");//时间
                        string videoName = GetVideoName(item.VideoId); //视频名称
                        string lineState=GetOther(item.GroupUserId, 3);//在线状态
                        IRow row1 = sheet1.CreateRow(rownum);
                        row1.CreateCell(0).SetCellValue(name);
                        row1.CreateCell(1).SetCellValue(ip);
                        row1.CreateCell(2).SetCellValue(StartTime);
                        row1.CreateCell(3).SetCellValue(videoName);
                        row1.CreateCell(4).SetCellValue(lineState); 
                        rownum++;
                    }
                    #endregion
                    using (MemoryStream ms = new MemoryStream())
                    {
                        workbook.Write(ms);
                        Response.ContentType = "application/vnd.ms-excel";
                        //DateTime.Now.ToString("yyyyMMddHHmmssfff")
                        Response.AddHeader("Content-Disposition"string.Format("attachment; filename={0}.xls","学习记录"));
                        Response.Clear();
                        Response.BinaryWrite(ms.ToArray());
                        workbook = null;
                    }
                }
                catch
                {
                    //JavaScriptManager.show("请确保导出的表格没有被打开!若打开了,请关闭后再导出!");
                }
            }
  • 相关阅读:
    使用form插件 和ajax 结合使用 没有调用success的原因
    不使用插件的ajax 上传文件
    struts2 使用ajax进行图片上传
    Java输入输出流详解
    SSM框架整合(Spring+SpringMVC+MyBatis+Oracle)
    Java WEB开发环境搭建以及创建Maven Web项目
    java连接Oracle数据库
    java轻量级IOC框架Guice
    Java String字符串方法
    python入门
  • 原文地址:https://www.cnblogs.com/nzcblog/p/4043295.html
Copyright © 2011-2022 走看看