Пример #1
1
        public XLStyle(IXLStylized container, IXLStyle initialStyle = null, Boolean useDefaultModify = true)
        {
            if (initialStyle != null)
            {
                Font = new XLFont(container, initialStyle.Font, useDefaultModify);
                Alignment = new XLAlignment(container, initialStyle.Alignment);
                Border = new XLBorder(container, initialStyle.Border, useDefaultModify);
                Fill = new XLFill(container, initialStyle.Fill, useDefaultModify);
                NumberFormat = new XLNumberFormat(container, initialStyle.NumberFormat);
                Protection = new XLProtection(container, initialStyle.Protection);
            }
            else
            {
                Font = new XLFont(container, null);
                Alignment = new XLAlignment(container);
                Border = new XLBorder(container, null);
                Fill = new XLFill(container);
                NumberFormat = new XLNumberFormat(container, null);
                Protection = new XLProtection(container);
            }

            DateFormat = NumberFormat;
        }
Пример #2
0
        public void Transpose(XLTransposeOptions transposeOption)
        {
            int rowCount    = RowCount();
            int columnCount = ColumnCount();
            int squareSide  = rowCount > columnCount ? rowCount : columnCount;

            var firstCell = FirstCell();

            MoveOrClearForTranspose(transposeOption, rowCount, columnCount);
            TransposeMerged(squareSide);
            TransposeRange(squareSide);
            RangeAddress.LastAddress = new XLAddress(Worksheet,
                                                     firstCell.Address.RowNumber + columnCount - 1,
                                                     firstCell.Address.ColumnNumber + rowCount - 1,
                                                     RangeAddress.LastAddress.FixedRow,
                                                     RangeAddress.LastAddress.FixedColumn);
            if (rowCount > columnCount)
            {
                var rng = Worksheet.Range(
                    RangeAddress.LastAddress.RowNumber + 1,
                    RangeAddress.FirstAddress.ColumnNumber,
                    RangeAddress.LastAddress.RowNumber + (rowCount - columnCount),
                    RangeAddress.LastAddress.ColumnNumber);
                rng.Delete(XLShiftDeletedCells.ShiftCellsUp);
            }
            else if (columnCount > rowCount)
            {
                var rng = Worksheet.Range(
                    RangeAddress.FirstAddress.RowNumber,
                    RangeAddress.LastAddress.ColumnNumber + 1,
                    RangeAddress.LastAddress.RowNumber,
                    RangeAddress.LastAddress.ColumnNumber + (columnCount - rowCount));
                rng.Delete(XLShiftDeletedCells.ShiftCellsLeft);
            }

            foreach (IXLCell c in Range(1, 1, columnCount, rowCount).Cells())
            {
                var border = new XLBorder(this, c.Style.Border);
                c.Style.Border.TopBorder         = border.LeftBorder;
                c.Style.Border.TopBorderColor    = border.LeftBorderColor;
                c.Style.Border.LeftBorder        = border.TopBorder;
                c.Style.Border.LeftBorderColor   = border.TopBorderColor;
                c.Style.Border.RightBorder       = border.BottomBorder;
                c.Style.Border.RightBorderColor  = border.BottomBorderColor;
                c.Style.Border.BottomBorder      = border.RightBorder;
                c.Style.Border.BottomBorderColor = border.RightBorderColor;
            }
        }
Пример #3
0
        internal static XLStyleKey GenerateKey(IXLStyle initialStyle)
        {
            if (initialStyle == null)
            {
                return(Default.Key);
            }
            if (initialStyle is XLStyle)
            {
                return((initialStyle as XLStyle).Key);
            }

            return(new XLStyleKey
            {
                Font = XLFont.GenerateKey(initialStyle.Font),
                Alignment = XLAlignment.GenerateKey(initialStyle.Alignment),
                Border = XLBorder.GenerateKey(initialStyle.Border),
                Fill = XLFill.GenerateKey(initialStyle.Fill),
                NumberFormat = XLNumberFormat.GenerateKey(initialStyle.NumberFormat),
                Protection = XLProtection.GenerateKey(initialStyle.Protection)
            });
        }
Пример #4
0
        public XLStyle(IXLStylized container, IXLStyle initialStyle = null, Boolean useDefaultModify = true)
        {
            if (initialStyle != null)
            {
                Font         = new XLFont(container, initialStyle.Font, useDefaultModify);
                Alignment    = new XLAlignment(container, initialStyle.Alignment);
                Border       = new XLBorder(container, initialStyle.Border, useDefaultModify);
                Fill         = new XLFill(container, initialStyle.Fill, useDefaultModify);
                NumberFormat = new XLNumberFormat(container, initialStyle.NumberFormat);
                Protection   = new XLProtection(container, initialStyle.Protection);
            }
            else
            {
                Font         = new XLFont(container, null);
                Alignment    = new XLAlignment(container);
                Border       = new XLBorder(container, null);
                Fill         = new XLFill(container);
                NumberFormat = new XLNumberFormat(container, null);
                Protection   = new XLProtection(container);
            }

            DateFormat = NumberFormat;
        }
        private bool BordersAreEqual(Border b, IXLBorder xlBorder)
        {
            var nb = new XLBorder();
            if (b.DiagonalUp != null)
                nb.DiagonalUp = b.DiagonalUp.Value;

            if (b.DiagonalDown != null)
                nb.DiagonalDown = b.DiagonalDown.Value;

            if (b.LeftBorder != null)
            {
                if (b.LeftBorder.Style != null)
                    nb.LeftBorder = b.LeftBorder.Style.Value.ToClosedXml();
                var bColor = GetColor(b.LeftBorder.Color);
                if (bColor.HasValue)
                    nb.LeftBorderColor = bColor;
            }

            if (b.RightBorder != null)
            {
                if (b.RightBorder.Style != null)
                    nb.RightBorder = b.RightBorder.Style.Value.ToClosedXml();
                var bColor = GetColor(b.RightBorder.Color);
                if (bColor.HasValue)
                    nb.RightBorderColor = bColor;
            }

            if (b.TopBorder != null)
            {
                if (b.TopBorder.Style != null)
                    nb.TopBorder = b.TopBorder.Style.Value.ToClosedXml();
                var bColor = GetColor(b.TopBorder.Color);
                if (bColor.HasValue)
                    nb.TopBorderColor = bColor;
            }

            if (b.BottomBorder != null)
            {
                if (b.BottomBorder.Style != null)
                    nb.BottomBorder = b.BottomBorder.Style.Value.ToClosedXml();
                var bColor = GetColor(b.BottomBorder.Color);
                if (bColor.HasValue)
                    nb.BottomBorderColor = bColor;
            }

            return nb.Equals(xlBorder);
        }
Пример #6
0
        public void Transpose(XLTransposeOptions transposeOption)
        {
            int rowCount = RowCount();
            int columnCount = ColumnCount();
            int squareSide = rowCount > columnCount ? rowCount : columnCount;

            var firstCell = FirstCell();

            MoveOrClearForTranspose(transposeOption, rowCount, columnCount);
            TransposeMerged(squareSide);
            TransposeRange(squareSide);
            RangeAddress.LastAddress = new XLAddress(Worksheet,
                                                     firstCell.Address.RowNumber + columnCount - 1,
                                                     firstCell.Address.ColumnNumber + rowCount - 1,
                                                     RangeAddress.LastAddress.FixedRow,
                                                     RangeAddress.LastAddress.FixedColumn);
            if (rowCount > columnCount)
            {
                var rng = Worksheet.Range(
                    RangeAddress.LastAddress.RowNumber + 1,
                    RangeAddress.FirstAddress.ColumnNumber,
                    RangeAddress.LastAddress.RowNumber + (rowCount - columnCount),
                    RangeAddress.LastAddress.ColumnNumber);
                rng.Delete(XLShiftDeletedCells.ShiftCellsUp);
            }
            else if (columnCount > rowCount)
            {
                var rng = Worksheet.Range(
                    RangeAddress.FirstAddress.RowNumber,
                    RangeAddress.LastAddress.ColumnNumber + 1,
                    RangeAddress.LastAddress.RowNumber,
                    RangeAddress.LastAddress.ColumnNumber + (columnCount - rowCount));
                rng.Delete(XLShiftDeletedCells.ShiftCellsLeft);
            }

            foreach (IXLCell c in Range(1, 1, columnCount, rowCount).Cells())
            {
                var border = new XLBorder(this, c.Style.Border);
                c.Style.Border.TopBorder = border.LeftBorder;
                c.Style.Border.TopBorderColor = border.LeftBorderColor;
                c.Style.Border.LeftBorder = border.TopBorder;
                c.Style.Border.LeftBorderColor = border.TopBorderColor;
                c.Style.Border.RightBorder = border.BottomBorder;
                c.Style.Border.RightBorderColor = border.BottomBorderColor;
                c.Style.Border.BottomBorder = border.RightBorder;
                c.Style.Border.BottomBorderColor = border.RightBorderColor;
            }
        }