Example #1
0
        protected void SetCellType(ref ICell cell, ExcelCellNumericTypeEnum enumExcelNumericType, ExcelCellAreaTypeEnum enumExcelCellAreaType)
        {
            ExcelCellStyle _ecsTarget = this.m_ecsList.Find(p => p.ExcelCellNumericType == enumExcelNumericType && p.ExcelCellAreaType == enumExcelCellAreaType);

            if (_ecsTarget == null)
            {
                ICellStyle _cellstyle = this.m_xssfWorkbook.CreateCellStyle();

                switch (enumExcelNumericType)
                {
                case ExcelCellNumericTypeEnum.NonNumeric:
                    break;

                case ExcelCellNumericTypeEnum.Integer:
                    _cellstyle.DataFormat = this.m_xssfWorkbook.CreateDataFormat().GetFormat("#,##0");
                    break;

                case ExcelCellNumericTypeEnum.Percentage:
                    _cellstyle.DataFormat = this.m_xssfWorkbook.CreateDataFormat().GetFormat("0%");
                    break;

                case ExcelCellNumericTypeEnum.PercentageOnSecondDecimalPoint:
                    _cellstyle.DataFormat = this.m_xssfWorkbook.CreateDataFormat().GetFormat("0.00%");
                    break;
                }

                IFont _font = this.m_xssfWorkbook.CreateFont();

                switch (enumExcelCellAreaType)
                {
                case ExcelCellAreaTypeEnum.Normal:
                    break;

                case ExcelCellAreaTypeEnum.Title:
                    _cellstyle.Alignment = HorizontalAlignment.Center;
                    _font.Boldweight     = (short)FontBoldWeight.Bold;
                    _cellstyle.SetFont(_font);
                    break;

                case ExcelCellAreaTypeEnum.SubSummary:
                    _font.Boldweight = (short)FontBoldWeight.Bold;
                    _cellstyle.SetFont(_font);
                    _cellstyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Lime.Index;
                    _cellstyle.FillPattern         = NPOI.SS.UserModel.FillPattern.SolidForeground;
                    break;

                case ExcelCellAreaTypeEnum.Summary:
                    _font.Boldweight = (short)FontBoldWeight.Bold;
                    _cellstyle.SetFont(_font);
                    _cellstyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Yellow.Index;
                    _cellstyle.FillPattern         = NPOI.SS.UserModel.FillPattern.SolidForeground;
                    break;
                }

                _ecsTarget = new ExcelCellStyle(enumExcelNumericType, enumExcelCellAreaType, _cellstyle);
                this.m_ecsList.Add(_ecsTarget);
            }

            cell.CellStyle = _ecsTarget.Style;
        }
Example #2
0
 public ExcelCellStyle(ExcelCellNumericTypeEnum enumExcelCellNumericType, ExcelCellAreaTypeEnum enumExcelCellAreaType, ICellStyle icellStyle)
 {
     this.ExcelCellNumericType = enumExcelCellNumericType;
     this.ExcelCellAreaType    = enumExcelCellAreaType;
     this.Style = icellStyle;
 }