Пример #1
0
        /// <summary>
        /// Fills a <see cref="OfficeOpenXml.Style.ExcelStyle" /> object with model data.
        /// </summary>
        /// <param name="style"><see cref="OfficeOpenXml.Style.ExcelStyle" /> object.</param>
        /// <param name="model">Style model definition.</param>
        /// <param name="useAlternate"><b>true</b> for use alternate color; Otherwise <b></b>.</param>
        /// <exception cref="System.ArgumentNullException">If <paramref name="style" /> is <c>null</c>.</exception>
        /// <exception cref="System.ArgumentNullException">If <paramref name="model" /> is <c>null</c>.</exception>
        public static void FormatFromModel(this ExcelStyle style, StyleModel model, bool useAlternate = false)
        {
            SentinelHelper.ArgumentNull(style);
            SentinelHelper.ArgumentNull(model);

            var hasInheritStyle = !string.IsNullOrEmpty(model.Inherits);

            if (hasInheritStyle)
            {
                var inheritStyle = model.TryGetInheritStyle();
                model.Combine(inheritStyle);
            }

            style.Font.SetFromFont(model.Font.ToFont());
            style.Font.Color.SetColor(model.Font.GetColor());

            var content = model.Content;

            style.VerticalAlignment   = content.Alignment.Vertical.ToEppVerticalAlignment();
            style.HorizontalAlignment = content.Alignment.Horizontal.ToEppHorizontalAlignment();

            style.Fill.PatternType = content.Pattern.PatternType.ToEppPatternFillStyle();
            if (style.Fill.PatternType != ExcelFillStyle.None)
            {
                style.Fill.BackgroundColor.SetColor(useAlternate ? content.GetAlternateColor() : content.GetColor());
                style.Fill.PatternColor.SetColor(content.Pattern.GetColor());
            }

            style.Numberformat.Format = content.DataType.GetDataFormat().ToEppDataFormat(content.DataType);

            foreach (var border in model.Borders)
            {
                style.Border.CreateFromModel(border);
            }
        }