Esempio n. 1
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);
        }