示例#1
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 = new XLRangeAddress(
                RangeAddress.FirstAddress,
                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 = (c.Style as XLStyle).Value.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;
            }
        }
示例#2
0
 private void MoveOrClearForTranspose(XLTransposeOptions transposeOption, int rowCount, int columnCount)
 {
     if (transposeOption == XLTransposeOptions.MoveCells)
     {
         if (rowCount > columnCount)
         {
             InsertColumnsAfter(false, rowCount - columnCount, false);
         }
         else if (columnCount > rowCount)
         {
             InsertRowsBelow(false, columnCount - rowCount, false);
         }
     }
     else
     {
         if (rowCount > columnCount)
         {
             int toMove     = rowCount - columnCount;
             var rngToClear = Worksheet.Range(
                 RangeAddress.FirstAddress.RowNumber,
                 RangeAddress.LastAddress.ColumnNumber + 1,
                 RangeAddress.LastAddress.RowNumber,
                 RangeAddress.LastAddress.ColumnNumber + toMove);
             rngToClear.Clear();
         }
         else if (columnCount > rowCount)
         {
             int toMove     = columnCount - rowCount;
             var rngToClear = Worksheet.Range(
                 RangeAddress.LastAddress.RowNumber + 1,
                 RangeAddress.FirstAddress.ColumnNumber,
                 RangeAddress.LastAddress.RowNumber + toMove,
                 RangeAddress.LastAddress.ColumnNumber);
             rngToClear.Clear();
         }
     }
 }
示例#3
0
 private void MoveOrClearForTranspose(XLTransposeOptions transposeOption, int rowCount, int columnCount)
 {
     if (transposeOption == XLTransposeOptions.MoveCells)
     {
         if (rowCount > columnCount)
             InsertColumnsAfter(false, rowCount - columnCount, false);
         else if (columnCount > rowCount)
             InsertRowsBelow(false, columnCount - rowCount, false);
     }
     else
     {
         if (rowCount > columnCount)
         {
             int toMove = rowCount - columnCount;
             var rngToClear = Worksheet.Range(
                 RangeAddress.FirstAddress.RowNumber,
                 RangeAddress.LastAddress.ColumnNumber + 1,
                 RangeAddress.LastAddress.RowNumber,
                 RangeAddress.LastAddress.ColumnNumber + toMove);
             rngToClear.Clear();
         }
         else if (columnCount > rowCount)
         {
             int toMove = columnCount - rowCount;
             var rngToClear = Worksheet.Range(
                 RangeAddress.LastAddress.RowNumber + 1,
                 RangeAddress.FirstAddress.ColumnNumber,
                 RangeAddress.LastAddress.RowNumber + toMove,
                 RangeAddress.LastAddress.ColumnNumber);
             rngToClear.Clear();
         }
     }
 }
示例#4
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;
            }
        }