首页 > 代码库 > C#中联查的简单方法(如从数据库中获取到数据放到excel表中)

C#中联查的简单方法(如从数据库中获取到数据放到excel表中)

 var path = new FileStream((Server.MapPath("~") + "Content\\data\\Cause\\事业单位管理人员基本情况.xls"), FileMode.Open, FileAccess.Read);
            var wb = new HSSFWorkbook(path);
            var shet = wb.GetSheet("page 1");
            var chain = shet.Chain("D7");
            var rowFun = new List<Func<PersonInfo, bool>>
            {
                //合计
                m=>true,
                m=>m.Sex.Equals("女"),
                m=>!m.FamilyName.Contains("汉族"),
                m=>m.PoliticalFace.Contains("党员"),
                m=>m.HigthDeggee.Contains("博士"),    
                m=>m.HigthDeggee.Contains("硕士"),    
                m=>true, 
    
                m=>m.HigthDeggee.Contains("研究生"),
                m=>m.HigthDeggee.Contains("大学本科"),
                m=>m.HigthDeggee.Contains("大学专科"),
                m=>m.HigthDeggee.Contains("中专"),
                m=>m.HigthDeggee.Contains("高中及以下"),
                //年龄
                m=>m.AgeGroup.Contains("35岁及以下"),
                m=>m.AgeGroup.Contains("36岁至40岁"),
                m=>m.AgeGroup.Contains("41岁至45岁"),
                m=>m.AgeGroup.Contains("46岁至50岁"),
                m=>m.AgeGroup.Contains("51岁至54岁"),
                m=>m.AgeGroup.Contains("55岁至59岁"),
                m=>m.AgeGroup.Contains("60岁及以上"),


            };
            var colFun = new List<Func<PersonInfo, bool>>
            {
              
                m=>true,
        
                m=>m.Sex.Equals("女"),
               m=>!m.FamilyName.Contains("汉族"),  //少数名族
               m=>m.ManageGrage.Contains("一级职员"),
               m=>m.ManageGrage.Contains("二级职员"),
               m=>m.ManageGrage.Contains("三级职员"),
               m=>m.ManageGrage.Contains("四级职员"),
               m=>m.ManageGrage.Contains("五级职员"),
                m=>m.ManageGrage.Contains("六级职员"),
                m=>m.ManageGrage.Contains("七级职员"),
                m=>m.ManageGrage.Contains("八级职员"),
                m=>m.ManageGrage.Contains("九级职员"),
                m=>m.ManageGrage.Contains("十级职员"),
                m=>m.ManageGrage.Contains("其他等级"),
                //非在册正式人员
            m=>!m.LaborForm.Contains("正式在编")&&!m.LaborForm.Contains("劳务派遣"),
        
            };
   
                var person = session.Find<PersonInfo>(); //这是我们自己封装的类,查询表中的数据
                for (var k = 0; k < colFun.Count; k++)
                {
                    var col = colFun[k];
                    for (var i = 0; i < rowFun.Count; i++)
                    {
                        var row = rowFun[i];

                            var result = person.Where(col).Where(row).ToList();
                            chain.Output(result.Count());   //output是我们自己封装的类,自动换到下一个框里
                   

                    }


                    chain.NextRow();   //nexnow是我们自己封装的类,自动换到下一行里,如自己导出行数+1即可
                }
            下面直接导出就可以了
           

C#中联查的简单方法(如从数据库中获取到数据放到excel表中)