Ejemplo n.º 1
0
        public static void fillcompToData(SqlDataReader dr, ISheet sheet, IRow row, ICellStyle datastyle, IFont datafont, ICellStyle style, IFont font, int rowIndex)
        {
            //设置列宽
            sheet.SetColumnWidth(0, 5500);
            sheet.SetColumnWidth(1, 5500);
            sheet.SetColumnWidth(2, 3700);
            sheet.SetColumnWidth(3, 5000);
            sheet.SetColumnWidth(4, 9000);

            //设置行高
            sheet.DefaultRowHeight = 350;

            //表头数据
            ICell cell0 = row.CreateCell(0);

            cell0.SetCellValue("开始时间");
            cell0.CellStyle = style;

            ICell cell1 = row.CreateCell(1);

            cell1.SetCellValue("结束时间");
            cell1.CellStyle = style;

            ICell cell2 = row.CreateCell(2);

            cell2.SetCellValue("报警个数");
            cell2.CellStyle = style;


            ICell cell3 = row.CreateCell(3);

            cell3.SetCellValue("10Min平均报警率");
            cell3.CellStyle = style;

            ICell cell4 = row.CreateCell(4);

            cell4.SetCellValue("报警位号");
            cell4.CellStyle = style;

            //填充数据
            if (null != dr)
            {
                while (dr.Read())
                {
                    rowIndex++;
                    row = sheet.CreateRow(rowIndex);

                    cell0 = row.CreateCell(0);
                    cell0.SetCellValue(BeanTools.DataTimeToString(dr["ZHStartTime"]));
                    cell0.CellStyle = datastyle;

                    cell1 = row.CreateCell(1);
                    cell1.SetCellValue(BeanTools.DataTimeToString(dr["ZHEndTime"]));
                    cell1.CellStyle = datastyle;


                    cell2 = row.CreateCell(2);
                    cell2.SetCellValue(BeanTools.ObjectToString(dr["ZHErrorCount"]));
                    cell2.CellStyle           = datastyle;
                    cell2.CellStyle.Alignment = HorizontalAlignment.RIGHT;

                    cell3 = row.CreateCell(3);
                    cell3.SetCellValue(Math.Round(BeanTools.ObjectToDouble(dr["ZHPercent"]), 7));
                    cell3.CellStyle           = datastyle;
                    cell3.CellStyle.Alignment = HorizontalAlignment.RIGHT;

                    string startTime = BeanTools.ObjectToString(dr["ZHAlarmItems"]);
                    cell4 = row.CreateCell(4);
                    cell4.SetCellValue(startTime);
                    cell4.CellStyle           = datastyle;
                    cell3.CellStyle.Alignment = HorizontalAlignment.LEFT;
                }
            }
        }