internal IXLPicture CopyTo(XLWorksheet targetSheet)
        {
            if (targetSheet == null)
            {
                targetSheet = Worksheet as XLWorksheet;
            }

            IXLPicture newPicture;

            if (targetSheet == Worksheet)
            {
                newPicture = targetSheet.AddPicture(ImageStream, Format);
            }
            else
            {
                newPicture = targetSheet.AddPicture(ImageStream, Format, Name);
            }

            newPicture = newPicture
                         .WithPlacement(XLPicturePlacement.FreeFloating)
                         .WithSize(Width, Height)
                         .WithPlacement(Placement);

            switch (Placement)
            {
            case XLPicturePlacement.FreeFloating:
                newPicture.MoveTo(Left, Top);
                break;

            case XLPicturePlacement.Move:
                newPicture.MoveTo(targetSheet.Cell(TopLeftCell.Address), GetOffset(XLMarkerPosition.TopLeft));
                break;

            case XLPicturePlacement.MoveAndSize:
                newPicture.MoveTo(targetSheet.Cell(TopLeftCell.Address), GetOffset(XLMarkerPosition.TopLeft), targetSheet.Cell(BottomRightCell.Address),
                                  GetOffset(XLMarkerPosition.BottomRight));
                break;
            }

            return(newPicture);
        }
Beispiel #2
0
        internal void SwapRanges(XLSheetRange sheetRange1, XLSheetRange sheetRange2, XLWorksheet worksheet)
        {
            Int32 rowCount    = sheetRange1.LastPoint.Row - sheetRange1.FirstPoint.Row + 1;
            Int32 columnCount = sheetRange1.LastPoint.Column - sheetRange1.FirstPoint.Column + 1;

            for (int row = 0; row < rowCount; row++)
            {
                for (int column = 0; column < columnCount; column++)
                {
                    var sp1   = new XLSheetPoint(sheetRange1.FirstPoint.Row + row, sheetRange1.FirstPoint.Column + column);
                    var sp2   = new XLSheetPoint(sheetRange2.FirstPoint.Row + row, sheetRange2.FirstPoint.Column + column);
                    var cell1 = GetCell(sp1);
                    var cell2 = GetCell(sp2);

                    if (cell1 == null)
                    {
                        cell1 = worksheet.Cell(sp1.Row, sp1.Column);
                    }
                    if (cell2 == null)
                    {
                        cell2 = worksheet.Cell(sp2.Row, sp2.Column);
                    }

                    //if (cell1 != null)
                    //{
                    cell1.Address = new XLAddress(cell1.Worksheet, sp2.Row, sp2.Column, false, false);
                    Remove(sp1);
                    //if (cell2 != null)
                    Add(sp1, cell2);
                    //}

                    //if (cell2 == null) continue;

                    cell2.Address = new XLAddress(cell2.Worksheet, sp1.Row, sp1.Column, false, false);
                    Remove(sp2);
                    //if (cell1 != null)
                    Add(sp2, cell1);
                }
            }
        }
Beispiel #3
0
        private IEnumerable <XLCell> GetUsedCellsInRange(XLRangeAddress rangeAddress, XLWorksheet worksheet, IEnumerable <XLSheetPoint> usedCellsCandidates)
        {
            if (!rangeAddress.IsValid)
            {
                yield break;
            }
            var normalizedAddress = rangeAddress.Normalize();
            var minRow            = normalizedAddress.FirstAddress.RowNumber;
            var maxRow            = normalizedAddress.LastAddress.RowNumber;
            var minColumn         = normalizedAddress.FirstAddress.ColumnNumber;
            var maxColumn         = normalizedAddress.LastAddress.ColumnNumber;

            var cellRange = worksheet.Internals.CellsCollection
                            .GetCells(minRow, minColumn, maxRow, maxColumn, _predicate)
                            .Where(c => !c.IsEmpty(_options));

            foreach (var cell in cellRange)
            {
                if (_predicate(cell))
                {
                    yield return(cell);
                }
            }

            foreach (var sheetPoint in usedCellsCandidates)
            {
                if (sheetPoint.Row.Between(minRow, maxRow) &&
                    sheetPoint.Column.Between(minColumn, maxColumn))
                {
                    var cell = worksheet.Cell(sheetPoint.Row, sheetPoint.Column);

                    if (_predicate(cell))
                    {
                        yield return(cell);
                    }
                }
            }
        }
Beispiel #4
0
 protected override IExternalExcelCell CellInternal(int row, int col)
 {
     return(new CloseXMLExcelCell(_obj.Cell(row, col)));
 }