C#员工排名系统之总结

(1)using Aspose.Cells;此dill的引用需要.net目标框架为4.0

(2)自定义Excel导出格式样式和单元格格式(直接上代码)

  public void Daochu(string filepath)
        {
                Workbook workbook = new Workbook();
                Worksheet sheet = workbook.Worksheets[0];
                Cells cells = sheet.Cells;//单元格 
                ////为标题设置样式     
                Style styleTitle = workbook.CreateStyle();//新增样式 
                styleTitle.HorizontalAlignment = TextAlignmentType.Center;//文字居中 
                Style styleTitlerow = workbook.CreateStyle();//新增样式 
                styleTitlerow.VerticalAlignment = TextAlignmentType.Center;//文字居中 
                styleTitlerow.HorizontalAlignment = TextAlignmentType.Center;//文字居中 
                ////样式1 标题下方的日期
                //Style style1 = workbook.CreateStyle();//新增样式 
                //style1.HorizontalAlignment = TextAlignmentType.Center;//文字居中 
                //style1.Font.Name = "微软雅黑";//文字字体 
                //style1.Font.Size = 12;//文字大小 
                ////样式2 列名
                Style style2 = workbook.CreateStyle();//新增样式 
                style2.HorizontalAlignment = TextAlignmentType.Center;//文字居中 
                //style2.Font.Name = "微软雅黑";//文字字体 
                //style2.Font.Size = 12;//文字大小 
                //style2.Font.IsBold = true;//粗体 
                //style2.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
                //style2.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
                //style2.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
                //style2.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
                ////样式3 数据的样式
                //Style style3 = workbook.CreateStyle();//新增样式 
                //style3.HorizontalAlignment = TextAlignmentType.Center;//文字居中 
                //style3.Font.Name = "微软雅黑";//文字字体 
                //style3.Font.Size = 10;//文字大小 
                //style3.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
                //style3.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
                //style3.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
                //style3.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;

                int Rownum = list1.Count+list2.Count+baibanyuexinleijitime.Count+yebanyuexinleijitime.Count;//表格行数 

               
                //第一行和第二行前两列单元格合并,无数据
                cells.Merge(0, 0, 1, 2);//合并单元格 
                cells.Merge(1, 0, 1, 2);//合并单元格 
               //第一行列标题
                cells.Merge(0, 2, 1, 3);//合并单元格 
                cells[0, 2].PutValue("计件员工排序");//填写内容 
                cells[0, 2].SetStyle(styleTitle);
               //第二行列标题
                cells.SetColumnWidth(2,10);
                cells[1, 2].PutValue("姓名");//填写内容 
                cells[0, 0].SetStyle(styleTitle);
                cells.SetColumnWidth(3,10);
                cells[1, 3].PutValue("平均排名");//填写内容 
                cells[0, 0].SetStyle(styleTitle);
                cells.SetColumnWidth(4, 10);
                cells[1, 4].PutValue("上班天数");//填写内容 
                cells[0, 0].SetStyle(styleTitle);
                //第一列行标题
                cells.Merge(2, 0, list1.Count+baibanyuexinleijitime.Count,1);//合并单元格 
                cells[2,0].PutValue("白班");//填写内容 
                cells[2,0].SetStyle(styleTitlerow);
                cells.Merge(list1.Count + baibanyuexinleijitime.Count+2,0, list2.Count+yebanyuexinleijitime.Count, 1);//合并单元格 
                cells[list1.Count + baibanyuexinleijitime.Count + 2, 0].PutValue("夜班");//填写内容 
                cells[list1.Count + baibanyuexinleijitime.Count + 2, 0].SetStyle(styleTitlerow);
                //第二列行标题
                cells.Merge(2,1, list1.Count, 1);//合并单元格 
                cells[2, 1].PutValue("计件");//填写内容 
                cells[2, 1].SetStyle(styleTitlerow);
                cells.Merge(list1.Count + 2,1,baibanyuexinleijitime.Count, 1);//合并单元格 
                cells[list1.Count+ 2, 1].PutValue("月薪");//填写内容 
                cells[list1.Count+ 2, 1].SetStyle(styleTitlerow);
                cells.Merge(list1.Count + 2+baibanyuexinleijitime.Count, 1,list2.Count, 1);//合并单元格 
                cells[list1.Count + 2 + baibanyuexinleijitime.Count, 1].PutValue("计件");//填写内容 
                cells[list1.Count + 2 + baibanyuexinleijitime.Count, 1].SetStyle(styleTitlerow);
                cells.Merge(list1.Count + 2 + baibanyuexinleijitime.Count+list2.Count, 1,yebanyuexinleijitime.Count, 1);//合并单元格 
                cells[list1.Count + 2 + baibanyuexinleijitime.Count+list2.Count, 1].PutValue("月薪");//填写内容 
                cells[list1.Count + 2 + baibanyuexinleijitime.Count+list2.Count, 1].SetStyle(styleTitlerow);
                //数据行
               int temprow=2;
                for (int i = 0; i < list1.Count; i++)
                {
                    paiming p = list1[i];
                    cells[temprow, 2].PutValue(p.name);
                    cells[temprow, 2].SetStyle(style2);
                    cells[temprow, 3].PutValue(p.fenshu.ToString());
                    cells[temprow, 3].SetStyle(style2);
                    cells[temprow, 4].PutValue(p.days.ToString());
                    cells[temprow, 4].SetStyle(style2);
                    temprow++;
                }
                foreach (KeyValuePair pair in baibanyuexinleijitime)
                {
                    cells[temprow, 2].PutValue(pair.Key);
                    cells[temprow, 2].SetStyle(style2);
                    cells[temprow, 4].PutValue(pair.Value);
                    cells[temprow, 4].SetStyle(style2);
                    temprow++;
                }
                for (int i = 0; i < list2.Count; i++)
                {
                    paiming p = list2[i];
                    cells[temprow, 2].PutValue(p.name);
                    cells[temprow, 2].SetStyle(style2);
                    cells[temprow, 3].PutValue(p.fenshu.ToString());
                    cells[temprow, 3].SetStyle(style2);
                    cells[temprow, 4].PutValue(p.days.ToString());
                    cells[temprow, 4].SetStyle(style2);
                    temprow++;
                }
                foreach (KeyValuePair pair in yebanyuexinleijitime)
                {
                    cells[temprow, 2].PutValue(pair.Key);
                    cells[temprow, 2].SetStyle(style2);
                    cells[temprow, 4].PutValue(pair.Value);
                    cells[temprow, 4].SetStyle(style2);
                    temprow++;
                }
                workbook.Save(filepath);//生成Excel
        }


(3)指纹识别的应用

你可能感兴趣的:(C#员工排名系统之总结)