• 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("请确保导出的表格没有被打开!若打开了,请关闭后再导出!");
                }
            }
  • 相关阅读:
    JqueryValidate表单相同Name不校验问题解决
    钉钉SDK使用。
    禁用software reporter tool.exe 解决CPU高占用率的问题
    一个小巧,也很nice的“小日历”--一个Android App
    Android模拟器太慢怎么办?使用微软的VS模拟器
    windows10下录屏
    启明星会议室预订系统(企业微信)版发布
    JS图片压缩
    JS操作摄像头
    钉钉版会议室预订系统使用指南
  • 原文地址:https://www.cnblogs.com/nzcblog/p/4043295.html
Copyright © 2020-2023  润新知