Exemple #1
0
        /// <summary>
        /// Generate period header table.
        /// </summary>
        /// <param name="workbook">The npoi workbook interface.</param>
        /// <param name="sheet1">The npoi sheet interface.</param>
        /// <param name="rowIndex">The row target index.</param>
        private void GeneratePeriodHeaderTable(IWorkbook workbook, ISheet sheet1,
                                               int[] periodItemIds)
        {
            int startCellPeriod = 6;
            int startRowPeriod  = 5;
            var periodItemList  = _unitOfWork.GetRepository <PeriodItem>().GetCache(x => periodItemIds.Contains(x.Id),
                                                                                    orderBy: x => x.OrderBy(y => y.StartEvaDate));

            foreach (var item in periodItemList)
            {
                ExcelService.SetCellHeaderStyle(workbook, sheet1.GetRow(startRowPeriod), startCellPeriod, startCellPeriod + 2);
                ExcelService.SetCellHeaderStyle(workbook, sheet1.GetRow(startRowPeriod + 1), startCellPeriod, startCellPeriod + 2);
                ExcelService.SetCellHeaderStyle(workbook, sheet1.GetRow(startRowPeriod + 2), startCellPeriod, startCellPeriod + 2);
                ExcelService.CreateHeaderCell(workbook, sheet1, sheet1.GetRow(startRowPeriod), startCellPeriod, $"รอบการประเมิน {item.PeriodName}");
                ExcelService.CreateHeaderCell(workbook, sheet1, sheet1.GetRow(startRowPeriod + 1), startCellPeriod,
                                              this.GetPeriodDisplayTh(item.StartEvaDate.Value, item.EndEvaDate.Value));
                ExcelService.CreateHeaderCell(workbook, sheet1, sheet1.GetRow(startRowPeriod + 2), startCellPeriod, "เกรด");
                ExcelService.CreateHeaderCell(workbook, sheet1, sheet1.GetRow(startRowPeriod + 2), startCellPeriod + 1, "คะแนน");
                ExcelService.CreateHeaderCell(workbook, sheet1, sheet1.GetRow(startRowPeriod + 2), startCellPeriod + 2, "เกณฑ์การประเมิน");

                sheet1.AddMergedRegion(new CellRangeAddress(startRowPeriod, startRowPeriod, startCellPeriod, startCellPeriod + 2));
                sheet1.AddMergedRegion(new CellRangeAddress(startRowPeriod + 1, startRowPeriod + 1, startCellPeriod, startCellPeriod + 2));
                startCellPeriod = startCellPeriod + 3;
            }
        }
        /// <summary>
        /// Generate header table.
        /// </summary>
        /// <param name="workbook">The npoi workbook interface.</param>
        /// <param name="sheet1">The npoi sheet interface.</param>
        /// <param name="rowIndex">The row target index.</param>
        private void GenerateHeaderTable(IWorkbook workbook, ISheet sheet1,
                                         ref int rowIndex)
        {
            string[] mainHeaders = new string[]
            {
                "เลขที่ใบประเมิน",
                "บริษัท",
                "รอบการประเมิน",
                "รอบการประเมิน",
                "ชื่อรอบการประเมิน",
                "รหัสผู้ขาย",
                "ชื่อผู้ขาย",
                "ชื่อประเภทผู้ขาย",
                "ชื่อกลุ่มจัดซื้อ",
            };
            IRow headerRow = sheet1.CreateRow(rowIndex);

            headerRow.Height = 500;
            int cellHeaderIndex = 0;

            foreach (var item in mainHeaders)
            {
                ExcelService.SetCellHeaderStyle(workbook, headerRow, cellHeaderIndex);
                ExcelService.CreateHeaderCell(workbook, sheet1, headerRow, cellHeaderIndex, item);
                cellHeaderIndex++;
            }

            rowIndex++;
            IRow headerRow2 = sheet1.CreateRow(rowIndex);

            ExcelService.SetCellContentStyle(workbook, headerRow2, 0, cellHeaderIndex - 1);
        }
        /// <summary>
        /// Generate sub header table in report.
        /// </summary>
        /// <param name="workbook">The npoi workbook interface.</param>
        /// <param name="sheet1">The npoi sheet interface.</param>
        /// <param name="rowIndex">The row target index.</param>
        private void GenerateSubHeaderTable(IWorkbook workbook, ISheet sheet1,
                                            ref int rowIndex)
        {
            string[] mainHeaders = new string[]
            {
                "คะแนนที่ได้",
                "คะแนนเต็ม",
                "เกณฑ์การประเมินที่ได้",
                "เกณฑ์การประเมินที่ได้"
            };
            sheet1.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 6, 7));
            IRow headerRow       = sheet1.CreateRow(rowIndex);
            int  cellHeaderIndex = 4;

            foreach (var item in mainHeaders)
            {
                ExcelService.SetCellHeaderStyle(workbook, headerRow, cellHeaderIndex);
                ExcelService.CreateHeaderCell(workbook, sheet1, headerRow, cellHeaderIndex, item);
                cellHeaderIndex++;
            }
            rowIndex++;
        }
        /// <summary>
        /// Generate header table.
        /// </summary>
        /// <param name="workbook">The npoi workbook interface.</param>
        /// <param name="sheet1">The npoi sheet interface.</param>
        /// <param name="rowIndex">The row target index.</param>
        /// <param name="maxCountUser">The max count user for generate dynamic header column.</param>
        /// <param name="model">The filter criteria value.</param>
        /// <returns></returns>
        private int GenerateHeaderTable(IWorkbook workbook, ISheet sheet1,
                                        ref int rowIndex, int maxCountUser,
                                        InvestigateEvaluationReportRequestModel model)
        {
            IRow topicRow = sheet1.CreateRow(rowIndex);

            ExcelService.CreateTopicCell(workbook, sheet1, topicRow, 0, $"รายงานตรวจสอบสถานะการประเมิน - วันที่พิมพ์ {UtilityService.DateTimeToStringTH(DateTime.Now, "dd MMM yyyy")}");
            rowIndex = rowIndex + 1;
            IRow criteriaRow = sheet1.CreateRow(rowIndex);

            criteriaRow.Height = 3000;
            ExcelService.CreateCriteriaCell(workbook, sheet1, criteriaRow, 0, $"{this.GenerateCriteria(model)}");
            ExcelService.SetCellCriteriaStyle(workbook, criteriaRow, 1, 3);
            rowIndex = rowIndex + 2;
            string[] mainHeaders = new string[]
            {
                "เลขที่ใบประเมิน",
                "บริษัท",
                "รอบการประเมิน",
                "รอบการประเมิน",
                "รหัสผู้ขาย",
                "ชื่อผู้ขาย",
                "ชื่อประเภทผู้ขาย",
                "ชื่อกลุ่มจัดซื้อ",
                "จำนวนผู้ประเมิน",
                "ประเมินแล้วเสร็จ",
            };
            IRow headerRow = sheet1.CreateRow(rowIndex);

            headerRow.Height = 500;
            int cellHeaderIndex = 0;

            foreach (var item in mainHeaders)
            {
                ExcelService.SetCellHeaderStyle(workbook, headerRow, cellHeaderIndex);
                ExcelService.CreateHeaderCell(workbook, sheet1, headerRow, cellHeaderIndex, item);
                cellHeaderIndex++;
            }

            string[] userHeaders = new string[]
            {
                "ผู้ประเมิน",
                "สถานะ",
                "เหตุผล"
            };

            for (int i = 0; i < maxCountUser; i++)
            {
                foreach (var item in userHeaders)
                {
                    ExcelService.SetCellHeaderStyle(workbook, headerRow, cellHeaderIndex);
                    ExcelService.CreateHeaderCell(workbook, sheet1, headerRow, cellHeaderIndex, item);
                    sheet1.AddMergedRegion(new CellRangeAddress(5, 6, cellHeaderIndex, cellHeaderIndex));
                    cellHeaderIndex++;
                }
            }
            rowIndex++;
            IRow headerRow2 = sheet1.CreateRow(rowIndex);

            ExcelService.SetCellContentStyle(workbook, headerRow2, 0, cellHeaderIndex - 1);
            return(cellHeaderIndex);
        }