Ejemplo n.º 1
0
        public void Remove(Int32 row, Int32 column)
        {
            Count--;
            DecrementUsage(RowsUsed, row);
            DecrementUsage(ColumnsUsed, row);
            var sp = new XLSheetPoint(row, column);

            Deleted.Add(sp);
            _cellsDictionary.Remove(sp);
            //_cells[row, column] = null;
        }
Ejemplo n.º 2
0
        public XLCell GetCell(Int32 row, Int32 column)
        {
            if (row > MaxRowUsed || column > MaxColumnUsed)
            {
                return(null);
            }
            var    sp = new XLSheetPoint(row, column);
            XLCell cell;

            return(_cellsDictionary.TryGetValue(sp, out cell) ? cell : null);
        }
Ejemplo n.º 3
0
        public IEnumerable <XLSheetPoint> GetSheetPoints(Int32 rowStart, Int32 columnStart,
                                                         Int32 rowEnd, Int32 columnEnd)
        {
            int finalRow    = rowEnd > MaxRowUsed ? MaxRowUsed : rowEnd;
            int finalColumn = columnEnd > MaxColumnUsed ? MaxColumnUsed : columnEnd;

            for (int ro = rowStart; ro <= finalRow; ro++)
            {
                for (int co = columnStart; co <= finalColumn; co++)
                {
                    var sp = new XLSheetPoint(ro, co);
                    if (_cellsDictionary.ContainsKey(sp))
                    {
                        yield return(sp);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void RemoveAll(Int32 rowStart, Int32 columnStart,
                              Int32 rowEnd, Int32 columnEnd)
        {
            int finalRow    = rowEnd > MaxRowUsed ? MaxRowUsed : rowEnd;
            int finalColumn = columnEnd > MaxColumnUsed ? MaxColumnUsed : columnEnd;

            for (int ro = rowStart; ro <= finalRow; ro++)
            {
                for (int co = columnStart; co <= finalColumn; co++)
                {
                    var sp = new XLSheetPoint(ro, co);
                    if (_cellsDictionary.ContainsKey(sp))
                    {
                        Remove(sp);
                    }
                }
            }
        }
Ejemplo n.º 5
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);
                }
            }
        }
Ejemplo n.º 6
0
        public void Add(Int32 row, Int32 column, XLCell cell)
        {
            Count++;

            IncrementUsage(RowsUsed, row);
            IncrementUsage(ColumnsUsed, column);

            _cellsDictionary.Add(new XLSheetPoint(row, column), cell);
            if (row > MaxRowUsed)
            {
                MaxRowUsed = row;
            }
            if (column > MaxColumnUsed)
            {
                MaxColumnUsed = column;
            }
            var sp = new XLSheetPoint(row, column);

            if (Deleted.Contains(sp))
            {
                Deleted.Remove(sp);
            }
        }
Ejemplo n.º 7
0
 public void Remove(XLSheetPoint sheetPoint)
 {
     Remove(sheetPoint.Row, sheetPoint.Column);
 }
Ejemplo n.º 8
0
        public XLCell GetCell(XLSheetPoint sheetPoint)
        {
            XLCell cell;

            return(_cellsDictionary.TryGetValue(sheetPoint, out cell) ? cell : null);
        }
Ejemplo n.º 9
0
 public void Add(XLSheetPoint sheetPoint, XLCell cell)
 {
     Add(sheetPoint.Row, sheetPoint.Column, cell);
 }
Ejemplo n.º 10
0
        public IEnumerator <XLCell> GetEnumerator()
        {
            var     cellsInRanges = new Dictionary <XLWorksheet, HashSet <XLSheetPoint> >();
            Boolean oneRange      = _rangeAddresses.Count == 1;

            foreach (XLRangeAddress range in _rangeAddresses)
            {
                HashSet <XLSheetPoint> hash;
                if (cellsInRanges.ContainsKey(range.Worksheet))
                {
                    hash = cellsInRanges[range.Worksheet];
                }
                else
                {
                    hash = new HashSet <XLSheetPoint>();
                    cellsInRanges.Add(range.Worksheet, hash);
                }

                if (_usedCellsOnly)
                {
                    if (oneRange)
                    {
                        var cellRange = range
                                        .Worksheet
                                        .Internals
                                        .CellsCollection
                                        .GetCells(
                            range.FirstAddress.RowNumber,
                            range.FirstAddress.ColumnNumber,
                            range.LastAddress.RowNumber,
                            range.LastAddress.ColumnNumber)
                                        .Where(c => !c.IsEmpty(_includeFormats) &&
                                               (_predicate == null || _predicate(c))
                                               );

                        foreach (var cell in cellRange)
                        {
                            yield return(cell);
                        }
                    }
                    else
                    {
                        var tmpRange    = range;
                        var addressList = range.Worksheet.Internals.CellsCollection
                                          .GetSheetPoints(
                            tmpRange.FirstAddress.RowNumber,
                            tmpRange.FirstAddress.ColumnNumber,
                            tmpRange.LastAddress.RowNumber,
                            tmpRange.LastAddress.ColumnNumber);

                        foreach (XLSheetPoint a in addressList.Where(a => !hash.Contains(a)))
                        {
                            hash.Add(a);
                        }
                    }
                }
                else
                {
                    var mm = new MinMax
                    {
                        MinRow    = range.FirstAddress.RowNumber,
                        MaxRow    = range.LastAddress.RowNumber,
                        MinColumn = range.FirstAddress.ColumnNumber,
                        MaxColumn = range.LastAddress.ColumnNumber
                    };
                    if (mm.MaxRow > 0 && mm.MaxColumn > 0)
                    {
                        for (Int32 ro = mm.MinRow; ro <= mm.MaxRow; ro++)
                        {
                            for (Int32 co = mm.MinColumn; co <= mm.MaxColumn; co++)
                            {
                                if (oneRange)
                                {
                                    var c = range.Worksheet.Cell(ro, co);
                                    if (_predicate == null || _predicate(c))
                                    {
                                        yield return(c);
                                    }
                                }
                                else
                                {
                                    var address = new XLSheetPoint(ro, co);
                                    if (!hash.Contains(address))
                                    {
                                        hash.Add(address);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (!oneRange)
            {
                if (_usedCellsOnly)
                {
                    var cellRange = cellsInRanges
                                    .SelectMany(
                        cir =>
                        cir.Value.Select(a => cir.Key.Internals.CellsCollection.GetCell(a)).Where(
                            cell =>
                            cell != null &&
                            !cell.IsEmpty(_includeFormats) &&
                            (_predicate == null || _predicate(cell))
                            )
                        );

                    foreach (var cell in cellRange)
                    {
                        yield return(cell);
                    }
                }
                else
                {
                    foreach (var cir in cellsInRanges)
                    {
                        foreach (XLSheetPoint a in cir.Value)
                        {
                            var c = cir.Key.Cell(a.Row, a.Column);
                            if (_predicate == null || _predicate(c))
                            {
                                yield return(c);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
 public XLCell GetCell(XLSheetPoint sp)
 {
     return(GetCell(sp.Row, sp.Column));
 }
Ejemplo n.º 12
0
 public XLSheetRange(XLSheetPoint firstPoint, XLSheetPoint lastPoint)
 {
     FirstPoint = firstPoint;
     LastPoint  = lastPoint;
 }