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("请确保导出的表格没有被打开!若打开了,请关闭后再导出!");
                }
            }
  • 相关阅读:
    【阿里天池云-龙珠计划】薄书的机器学习笔记——快来一起挖掘幸福感!Task04
    薄书的pytorch项目实战lesson49-情感分类+蹭免费GPU
    薄书的博客园主题——awescnb
    # 详细分析MySQL事务日志(redo log和undo log)
    docker网络模式
    IOTOP
    磁盘分区知识
    # KVM虚拟化技术的内置快照和外置快照
    mysql MGR
    linux各种监控工具 (转)
  • 原文地址:https://www.cnblogs.com/nzcblog/p/4043295.html
Copyright © 2011-2022 走看看