Exemplo n.º 1
0
        /// <summary>
        /// Sets the horizontal alignment of a range.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <param name="horizontalAlignment">The horizontal alignment.</param>
        /// <param name="styleContainer">The style container.</param>
        /// <exception cref="ArgumentNullException"><paramref name="range"/> is null.</exception>
        public static void SetHorizontalAlignment(
            this Range range,
            HorizontalAlignment?horizontalAlignment,
            StyleContainer styleContainer = null)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            if (horizontalAlignment != null)
            {
                range.SetStyle(styleContainer, _ =>
                {
                    _.Style.HorizontalAlignment     = ((HorizontalAlignment)horizontalAlignment).ToTextAlignmentType();
                    _.StyleFlag.HorizontalAlignment = true;
                });
            }
        }
Exemplo n.º 2
0
        public static void SetCustomFormat(
            this Range range,
            string customFormatString,
            StyleContainer styleContainer = null)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            if (customFormatString != null)
            {
                range.SetStyle(styleContainer, _ =>
                {
                    _.Style.Custom           = customFormatString;
                    _.StyleFlag.NumberFormat = true;
                });
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sets the indent level for a range.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <param name="indentLevel">The indent level.</param>
        /// <param name="styleContainer">The style container.</param>
        /// <exception cref="ArgumentNullException"><paramref name="range"/> is null.</exception>
        public static void SetIndentLevel(
            this Range range,
            int?indentLevel,
            StyleContainer styleContainer = null)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            if (indentLevel != null)
            {
                range.SetStyle(styleContainer, _ =>
                {
                    _.Style.IndentLevel = (int)indentLevel;
                    _.StyleFlag.Indent  = true;
                });
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets the rotation angle for a range.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <param name="rotationAngle">The rotation angle.</param>
        /// <param name="styleContainer">The style container.</param>
        /// <exception cref="ArgumentNullException"><paramref name="range"/> is null.</exception>
        public static void SetFontRotationAngle(
            this Range range,
            int?rotationAngle,
            StyleContainer styleContainer = null)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            if (rotationAngle != null)
            {
                range.SetStyle(styleContainer, _ =>
                {
                    _.Style.RotationAngle = (int)rotationAngle;
                    _.StyleFlag.Rotation  = true;
                });
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sets the text format.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <param name="format">The format.</param>
        /// <param name="styleContainer">The style container.</param>
        /// <exception cref="ArgumentNullException"><paramref name="range"/> is null.</exception>
        public static void SetFormat(
            this Range range,
            Format?format,
            StyleContainer styleContainer = null)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            if (format != null)
            {
                range.SetStyle(styleContainer, _ =>
                {
                    _.Style.Number           = ((Format)format).ToFormatNumber();
                    _.StyleFlag.NumberFormat = true;
                });
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Sets text wrapping.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <param name="textIsWrapped">Determines whether text is wrapped.</param>
        /// <param name="styleContainer">The style container.</param>
        /// <exception cref="ArgumentNullException"><paramref name="range"/> is null.</exception>
        public static void SetTextIsWrapped(
            this Range range,
            bool?textIsWrapped,
            StyleContainer styleContainer = null)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            if (textIsWrapped != null)
            {
                range.SetStyle(styleContainer, _ =>
                {
                    _.Style.IsTextWrapped = (bool)textIsWrapped;
                    _.StyleFlag.WrapText  = true;
                });
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Sets underline on the font.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <param name="underlineKind">The kind of underline.</param>
        /// <param name="styleContainer">The style container.</param>
        /// <exception cref="ArgumentNullException"><paramref name="range"/> is null.</exception>
        public static void SetFontUnderline(
            this Range range,
            UnderlineKind?underlineKind,
            StyleContainer styleContainer = null)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            if (underlineKind != null)
            {
                range.SetStyle(styleContainer, _ =>
                {
                    _.Style.Font.Underline    = ((UnderlineKind)underlineKind).ToFontUnderlineType();
                    _.StyleFlag.FontUnderline = true;
                });
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Sets bold on the font.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <param name="fontIsBold">Determines whether the font is bold.</param>
        /// <param name="styleContainer">The style container.</param>
        /// <exception cref="ArgumentNullException"><paramref name="range"/> is null.</exception>
        public static void SetFontIsBold(
            this Range range,
            bool?fontIsBold,
            StyleContainer styleContainer = null)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            if (fontIsBold != null)
            {
                range.SetStyle(styleContainer, _ =>
                {
                    _.Style.Font.IsBold  = (bool)fontIsBold;
                    _.StyleFlag.FontBold = true;
                });
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Sets the font size for a range.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <param name="fontSize">The font size.</param>
        /// <param name="styleContainer">The style container.</param>
        /// <exception cref="ArgumentNullException"><paramref name="range"/> is null.</exception>
        public static void SetFontSize(
            this Range range,
            int?fontSize,
            StyleContainer styleContainer = null)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            if (fontSize != null)
            {
                range.SetStyle(styleContainer, _ =>
                {
                    _.Style.Font.Size    = (int)fontSize;
                    _.StyleFlag.FontSize = true;
                });
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Sets the font name for a range.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <param name="fontName">The font name.</param>
        /// <param name="styleContainer">The style container.</param>
        /// <exception cref="ArgumentNullException"><paramref name="range"/> is null.</exception>
        public static void SetFontName(
            this Range range,
            string fontName,
            StyleContainer styleContainer = null)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            if (fontName != null)
            {
                range.SetStyle(styleContainer, _ =>
                {
                    _.Style.Font.Name    = fontName;
                    _.StyleFlag.FontName = true;
                });
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Sets the font color for a range.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <param name="color">The color.</param>
        /// <param name="styleContainer">The style container.</param>
        /// <exception cref="ArgumentNullException"><paramref name="range"/> is null.</exception>
        public static void SetFontColor(
            this Range range,
            Color?color,
            StyleContainer styleContainer = null)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            if (color != null)
            {
                range.SetStyle(styleContainer, _ =>
                {
                    _.Style.Font.Color    = (Color)color;
                    _.StyleFlag.FontColor = true;
                });
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Sets the background color of a range.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <param name="color">The color.</param>
        /// <param name="styleContainer">The style container.</param>
        /// <exception cref="ArgumentNullException"><paramref name="range"/> is null.</exception>
        public static void SetBackgroundColor(
            this Range range,
            Color?color,
            StyleContainer styleContainer = null)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            if (color != null)
            {
                range.SetStyle(styleContainer, _ =>
                {
                    _.Style.Pattern         = BackgroundType.Solid;
                    _.Style.ForegroundColor = (Color)color;
                    _.StyleFlag.CellShading = true;
                });
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Applies the specified range style to the specified range.
        /// </summary>
        /// <param name="range">The range to apply to the style to.</param>
        /// <param name="rangeStyle">The style to apply.</param>
        /// <exception cref="ArgumentNullException"><paramref name="range"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="rangeStyle"/> is null.</exception>
        public static void SetRangeStyle(
            this Range range,
            RangeStyle rangeStyle)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            if (rangeStyle == null)
            {
                throw new ArgumentNullException(nameof(rangeStyle));
            }

            var styleContainer = StyleContainer.BuildNew(range.Worksheet.Workbook);

            range.SetBackgroundColor(rangeStyle.BackgroundColor, styleContainer);
            range.SetFontColor(rangeStyle.FontColor, styleContainer);
            range.SetFontName(rangeStyle.FontName, styleContainer);
            range.SetFontSize(rangeStyle.FontSize, styleContainer);
            range.SetFontIsItalic(rangeStyle.FontIsItalic, styleContainer);
            range.SetFontIsBold(rangeStyle.FontIsBold, styleContainer);
            range.SetFontUnderline(rangeStyle.FontUnderline, styleContainer);
            range.SetFontRotationAngle(rangeStyle.FontRotationAngle, styleContainer);
            range.SetTextIsWrapped(rangeStyle.TextIsWrapped, styleContainer);
            range.SetFormat(rangeStyle.Format, styleContainer);
            range.SetCustomFormat(rangeStyle.CustomFormatString, styleContainer);
            range.SetIndentLevel(rangeStyle.IndentLevel, styleContainer);
            range.SetVerticalAlignment(rangeStyle.VerticalAlignment, styleContainer);
            range.SetHorizontalAlignment(rangeStyle.HorizontalAlignment, styleContainer);
            styleContainer.ApplyToRange(range);

            range.SetPerRowHeightInPixels(rangeStyle.RowHeightInPixels);
            range.SetPerColumnWidthInPixels(rangeStyle.ColumnWidthInPixels);
            range.SetAutofitRows(rangeStyle.AutofitRows);
            range.SetMergeCells(rangeStyle.MergeCells);
            range.SetInsideBorder(rangeStyle.InsideBorder);
            range.SetOutsideBorder(rangeStyle.OutsideBorder);
            range.SetDataValidation(rangeStyle.DataValidation);
        }