Esempio n. 1
0
        /// <summary>
        /// 设置数据单元格样式和字体
        /// </summary>
        /// <param name="workbook"></param>
        /// <param name="styleAttr"></param>
        /// <param name="fontAttr"></param>
        /// <returns></returns>

        public virtual ICellStyle SetDataCellStyleAndFont(IWorkbook workbook, DataStyleAttribute styleAttr, DataFontAttribute fontAttr)
        {
            //数据单元格默认样式
            ICellStyle defaultStyle = CreateDataCellStyle(workbook, styleAttr);

            defaultStyle.SetFont(CreateDataCellFont(workbook, fontAttr));
            return(defaultStyle);
        }
Esempio n. 2
0
 /// <summary>
 /// 创建数据样式和字体【步骤 6】
 /// </summary>
 /// <typeparam name="TExportDto">集合中元素的类</typeparam>
 /// <param name="workbook">工作册</param>
 /// <param name="worksheet">工作表</param>
 /// <param name="styleAttr">样式特征</param>
 /// <param name="fontAttr">字体特征</param>
 /// <returns></returns>
 protected abstract TCellStyle CreateDataStyleAndFont <TExportDto>(TWorkbook workbook, TSheet worksheet,
                                                                   DataStyleAttribute styleAttr, DataFontAttribute fontAttr) where TExportDto : class, new();
Esempio n. 3
0
        /// <summary>
        /// 设置数据单元格样式和字体
        /// </summary>
        /// <param name="cellStyle"></param>
        /// <param name="styleAttr"></param>
        /// <param name="fontAttr"></param>
        /// <returns></returns>

        public virtual void SetDataCellStyleAndFont(ExcelStyle cellStyle, DataStyleAttribute styleAttr, DataFontAttribute fontAttr)
        {
            //表头默认样式
            SetDataCellStyle(cellStyle, styleAttr);
            SetDataCellFont(cellStyle.Font, fontAttr);
        }
Esempio n. 4
0
        /// <summary>
        /// 设置数据单元格样式
        /// </summary>
        public virtual void SetDataCellStyle(ExcelStyle cellStyle, DataStyleAttribute styleAttr)
        {
            if (cellStyle == null)
            {
                return;
            }

            styleAttr = styleAttr ?? new DataStyleAttribute();

            if (!string.IsNullOrWhiteSpace(styleAttr.DataFormat))
            {
                cellStyle.Numberformat.Format = styleAttr.DataFormat;
            }
            cellStyle.ShrinkToFit = styleAttr.ShrinkToFit;
            cellStyle.WrapText    = styleAttr.WrapText;
            cellStyle.Hidden      = styleAttr.IsHidden;
            cellStyle.Locked      = styleAttr.IsLocked;
            cellStyle.WrapText    = styleAttr.WrapText;

            if (styleAttr.Indention > -1)
            {
                cellStyle.Indent = styleAttr.Indention;
            }
            if (styleAttr.Rotation > -1)
            {
                cellStyle.TextRotation = styleAttr.Rotation;
            }
            if (styleAttr.Alignment > -1)
            {
                cellStyle.HorizontalAlignment = (ExcelHorizontalAlignment)styleAttr.Alignment;
            }
            if (styleAttr.VerticalAlignment >= -1)
            {
                cellStyle.VerticalAlignment = (ExcelVerticalAlignment)styleAttr.VerticalAlignment;
            }

            //边框样式、颜色
            if (styleAttr.BorderLeft > -1)
            {
                cellStyle.Border.Left.Style = (ExcelBorderStyle)styleAttr.BorderLeft;

                if (styleAttr.LeftBorderColor > -1)
                {
                    cellStyle.Border.Left.Color.Indexed = styleAttr.LeftBorderColor;
                }
            }
            if (styleAttr.BorderRight > -1)
            {
                cellStyle.Border.Right.Style = (ExcelBorderStyle)styleAttr.BorderRight;

                if (styleAttr.RightBorderColor > -1)
                {
                    cellStyle.Border.Right.Color.Indexed = styleAttr.RightBorderColor;
                }
            }
            if (styleAttr.BorderTop > -1)
            {
                cellStyle.Border.Top.Style = (ExcelBorderStyle)styleAttr.BorderTop;

                if (styleAttr.TopBorderColor > -1)
                {
                    cellStyle.Border.Top.Color.Indexed = styleAttr.TopBorderColor;
                }
            }
            if (styleAttr.BorderBottom > -1)
            {
                cellStyle.Border.Bottom.Style = (ExcelBorderStyle)styleAttr.BorderBottom;

                if (styleAttr.BottomBorderColor > -1)
                {
                    cellStyle.Border.Bottom.Color.Indexed = styleAttr.BottomBorderColor;
                }
            }

            //对角线
            //cellStyle.BorderDiagonal = (BorderDiagonal)styleAttr.BorderDiagonal;
            if (styleAttr.BorderDiagonalLineStyle > -1)
            {
                cellStyle.Border.Diagonal.Style = (ExcelBorderStyle)styleAttr.BorderDiagonalLineStyle;

                if (styleAttr.BorderDiagonalColor > -1)
                {
                    cellStyle.Border.Diagonal.Color.Indexed = styleAttr.BorderDiagonalColor;
                }
            }

            //填充
            if (styleAttr.FillPattern > -1)
            {
                cellStyle.Fill.PatternType = (ExcelFillStyle)styleAttr.FillPattern;

                if (styleAttr.FillBackgroundColor > -1)
                {
                    cellStyle.Fill.BackgroundColor.Indexed = styleAttr.FillBackgroundColor;
                }
            }
            //cellStyle.Fill.ForegroundColor = styleAttr.FillForegroundColor;
        }
Esempio n. 5
0
        /// <summary>
        /// 创建数据单元格样式
        /// </summary>
        public virtual ICellStyle CreateDataCellStyle(IWorkbook workbook, DataStyleAttribute styleAttr)
        {
            ICellStyle cellStyle = workbook.CreateCellStyle();

            styleAttr = styleAttr ?? new DataStyleAttribute();

            if (!string.IsNullOrWhiteSpace(styleAttr.DataFormat))
            {
                cellStyle.DataFormat = workbook.CreateDataFormat().GetFormat(styleAttr.DataFormat);
            }
            cellStyle.ShrinkToFit = styleAttr.ShrinkToFit;
            cellStyle.IsHidden    = styleAttr.IsHidden;
            cellStyle.IsLocked    = styleAttr.IsLocked;
            cellStyle.WrapText    = styleAttr.WrapText;

            if (styleAttr.Indention > -1)
            {
                cellStyle.Indention = styleAttr.Indention;
            }
            if (styleAttr.Rotation > -1)
            {
                cellStyle.Rotation = styleAttr.Rotation;
            }
            if (styleAttr.BorderLeft > -1)
            {
                cellStyle.BorderLeft = (BorderStyle)styleAttr.BorderLeft;
            }
            if (styleAttr.BorderRight > -1)
            {
                cellStyle.BorderRight = (BorderStyle)styleAttr.BorderRight;
            }
            if (styleAttr.BorderTop > -1)
            {
                cellStyle.BorderTop = (BorderStyle)styleAttr.BorderTop;
            }
            if (styleAttr.BorderBottom > -1)
            {
                cellStyle.BorderBottom = (BorderStyle)styleAttr.BorderBottom;
            }
            if (styleAttr.LeftBorderColor > -1)
            {
                cellStyle.LeftBorderColor = styleAttr.LeftBorderColor;
            }
            if (styleAttr.RightBorderColor > -1)
            {
                cellStyle.RightBorderColor = styleAttr.RightBorderColor;
            }
            if (styleAttr.TopBorderColor > -1)
            {
                cellStyle.TopBorderColor = styleAttr.TopBorderColor;
            }
            if (styleAttr.BottomBorderColor > -1)
            {
                cellStyle.BottomBorderColor = styleAttr.BottomBorderColor;
            }
            if (styleAttr.FillPattern > -1)
            {
                cellStyle.FillPattern = (FillPattern)styleAttr.FillPattern;
            }
            if (styleAttr.FillBackgroundColor > -1)
            {
                cellStyle.FillBackgroundColor = styleAttr.FillBackgroundColor;
            }
            if (styleAttr.FillForegroundColor > -1)
            {
                cellStyle.FillForegroundColor = styleAttr.FillForegroundColor;
            }
            if (styleAttr.BorderDiagonalColor > -1)
            {
                cellStyle.BorderDiagonalColor = styleAttr.BorderDiagonalColor;
            }
            if (styleAttr.BorderDiagonalLineStyle > -1)
            {
                cellStyle.BorderDiagonalLineStyle = (BorderStyle)styleAttr.BorderDiagonalLineStyle;
            }
            if (styleAttr.BorderDiagonal > -1)
            {
                cellStyle.BorderDiagonal = (BorderDiagonal)styleAttr.BorderDiagonal;
            }
            if (styleAttr.Alignment > -1)
            {
                cellStyle.Alignment = (HorizontalAlignment)styleAttr.Alignment;
            }
            if (styleAttr.VerticalAlignment > -1)
            {
                cellStyle.VerticalAlignment = (VerticalAlignment)styleAttr.VerticalAlignment;
            }


            return(cellStyle);
        }
 protected override ExcelStyle CreateDataStyleAndFont <TExportDto>(ExcelWorkbook workbook, ExcelWorksheet worksheet,
                                                                   DataStyleAttribute styleAttr, DataFontAttribute fontAttr)
 {
     return(null);
 }
Esempio n. 7
0
 protected override ICellStyle CreateDataStyleAndFont <TExportDto>(IWorkbook workbook, ISheet worksheet, DataStyleAttribute styleAttr, DataFontAttribute fontAttr)
 {
     return(_npoiCellStyleHandle.SetDataCellStyleAndFont(workbook, styleAttr, fontAttr));
 }