internal XLRangeColumn LastColumnUsed(XLCellsUsedOptions options, Func <IXLRangeColumn, Boolean> predicate = null)
        {
            if (predicate == null)
            {
                Int32 lastColumnUsed = Worksheet.Internals.CellsCollection.LastColumnUsed(
                    RangeAddress.FirstAddress.RowNumber,
                    RangeAddress.FirstAddress.ColumnNumber,
                    RangeAddress.LastAddress.RowNumber,
                    RangeAddress.LastAddress.ColumnNumber,
                    options);

                return(lastColumnUsed == 0 ? null : Column(lastColumnUsed - RangeAddress.FirstAddress.ColumnNumber + 1));
            }

            Int32 columnCount = ColumnCount();

            for (Int32 co = columnCount; co >= 1; co--)
            {
                var column = Column(co);

                if (!column.IsEmpty(options) && predicate(column))
                {
                    return(column);
                }
            }
            return(null);
        }
        internal XLRangeRow LastRowUsed(XLCellsUsedOptions options, Func <IXLRangeRow, Boolean> predicate = null)
        {
            if (predicate == null)
            {
                Int32 lastRowUsed = Worksheet.Internals.CellsCollection.LastRowUsed(
                    RangeAddress.FirstAddress.RowNumber,
                    RangeAddress.FirstAddress.ColumnNumber,
                    RangeAddress.LastAddress.RowNumber,
                    RangeAddress.LastAddress.ColumnNumber,
                    options);

                return(lastRowUsed == 0 ? null : Row(lastRowUsed - RangeAddress.FirstAddress.RowNumber + 1));
            }

            Int32 rowCount = RowCount();

            for (Int32 ro = rowCount; ro >= 1; ro--)
            {
                var row = Row(ro);

                if (!row.IsEmpty(options) && predicate(row))
                {
                    return(row);
                }
            }
            return(null);
        }
        internal XLRangeRow FirstRowUsed(XLCellsUsedOptions options, Func <IXLRangeRow, Boolean> predicate = null)
        {
            if (predicate == null)
            {
                Int32 rowFromCells = Worksheet.Internals.CellsCollection.FirstRowUsed(
                    RangeAddress.FirstAddress.RowNumber,
                    RangeAddress.FirstAddress.ColumnNumber,
                    RangeAddress.LastAddress.RowNumber,
                    RangeAddress.LastAddress.ColumnNumber,
                    options);

                //Int32 rowFromRows = Worksheet.Internals.RowsCollection.FirstRowUsed(includeFormats);

                return(rowFromCells == 0 ? null : Row(rowFromCells - RangeAddress.FirstAddress.RowNumber + 1));
            }

            Int32 rowCount = RowCount();

            for (Int32 ro = 1; ro <= rowCount; ro++)
            {
                var row = Row(ro);

                if (!row.IsEmpty(options) && predicate(row))
                {
                    return(row);
                }
            }
            return(null);
        }
Example #4
0
        internal override XLRangeColumns ColumnsUsed(XLCellsUsedOptions options, Func <IXLRangeColumn, bool> predicate = null)
        {
            var columns = base.ColumnsUsed(options, predicate);

            columns.Cast <XLRangeColumn>().ForEach(column => column.Table = this);
            return(columns);
        }
Example #5
0
 public XLCells(bool usedCellsOnly, XLCellsUsedOptions options, Func <IXLCell, Boolean> predicate = null)
     : base(XLStyle.Default.Value)
 {
     _usedCellsOnly = usedCellsOnly;
     _options       = options;
     _predicate     = predicate ?? (_ => true);
 }
        public IXLCells CellsUsed(XLCellsUsedOptions options)
        {
            var cells = new XLCells(false, options);

            foreach (XLTableRow container in _ranges)
            {
                cells.Add(container.RangeAddress);
            }
            return(cells);
        }
Example #7
0
        public IXLCells CellsUsed(XLCellsUsedOptions options)
        {
            var cells = new XLCells(true, options);

            foreach (XLColumn container in _columns)
            {
                cells.Add(container.RangeAddress);
            }
            return(cells);
        }
Example #8
0
        public IXLCells CellsUsed(XLCellsUsedOptions options)
        {
            var cells = new XLCells(usedCellsOnly: true, options: options);

            foreach (XLRangeColumn container in _ranges)
            {
                cells.Add(container.RangeAddress);
            }
            return(cells);
        }
Example #9
0
        public override Boolean IsEmpty(XLCellsUsedOptions options)
        {
            if (options.HasFlag(XLCellsUsedOptions.NormalFormats) &&
                !StyleValue.Equals(Worksheet.StyleValue))
            {
                return(false);
            }

            return(base.IsEmpty(options));
        }
        internal XLRangeRows RowsUsed(XLCellsUsedOptions options, Func <IXLRangeRow, Boolean> predicate = null)
        {
            XLRangeRows rows     = new XLRangeRows();
            Int32       rowCount = RowCount();

            for (Int32 ro = 1; ro <= rowCount; ro++)
            {
                var row = Row(ro);

                if (!row.IsEmpty(options) && (predicate == null || predicate(row)))
                {
                    rows.Add(row);
                }
            }
            return(rows);
        }
        internal virtual XLRangeColumns ColumnsUsed(XLCellsUsedOptions options, Func <IXLRangeColumn, Boolean> predicate = null)
        {
            XLRangeColumns columns     = new XLRangeColumns();
            Int32          columnCount = ColumnCount();

            for (Int32 co = 1; co <= columnCount; co++)
            {
                var column = Column(co);

                if (!column.IsEmpty(options) && (predicate == null || predicate(column)))
                {
                    columns.Add(column);
                }
            }
            return(columns);
        }
        internal XLTableRow FirstRowUsed(XLCellsUsedOptions options, Func <IXLTableRow, Boolean> predicate = null)
        {
            if (predicate == null)
            {
                return(new XLTableRow(this, (_range.FirstRowUsed(options))));
            }

            Int32 rowCount = _range.RowCount();

            for (Int32 ro = 1; ro <= rowCount; ro++)
            {
                var row = new XLTableRow(this, (_range.Row(ro)));

                if (!row.IsEmpty(options) && predicate(row))
                {
                    return(row);
                }
            }

            return(null);
        }
 IXLTableRow IXLTableRange.FirstRowUsed(XLCellsUsedOptions options, Func <IXLTableRow, Boolean> predicate)
 {
     return(FirstRowUsed(options, predicate));
 }
Example #14
0
 public IXLRangeColumn ColumnUsed(XLCellsUsedOptions options = XLCellsUsedOptions.AllContents)
 {
     return(Column((this as IXLRangeBase).FirstCellUsed(options),
                   (this as IXLRangeBase).LastCellUsed(options)));
 }
 public static IXLCells CellsUsedWithoutFormulas(this IXLRangeBase range, XLCellsUsedOptions options, Func <IXLCell, bool> predicate)
 {
     return(range.CellsUsed(options, c => predicate(c) && !c.HasFormula));
 }
 public static IXLCells CellsUsedWithoutFormulas(this IXLRangeBase range, XLCellsUsedOptions options)
 {
     return(range.CellsUsed(options, c => !c.HasFormula));
 }
 public static XLClearOptions ToClearOptions(this XLCellsUsedOptions options)
 {
     return((XLClearOptions)options);
 }
 IXLRangeColumn IXLRange.LastColumnUsed(XLCellsUsedOptions options, Func <IXLRangeColumn, Boolean> predicate)
 {
     return(LastColumnUsed(options, predicate));
 }
Example #19
0
 public IXLRangeRow RowUsed(XLCellsUsedOptions options = XLCellsUsedOptions.AllContents)
 {
     return(Row((this as IXLRangeBase).FirstCellUsed(options),
                (this as IXLRangeBase).LastCellUsed(options)));
 }
        public int LastColumnUsed(int rowStart, int columnStart, int rowEnd, int columnEnd, XLCellsUsedOptions options,
                                  Func <IXLCell, Boolean> predicate = null)
        {
            int maxCo       = 0;
            int finalRow    = rowEnd > MaxRowUsed ? MaxRowUsed : rowEnd;
            int finalColumn = columnEnd > MaxColumnUsed ? MaxColumnUsed : columnEnd;

            for (int ro = finalRow; ro >= rowStart; ro--)
            {
                if (rowsCollection.TryGetValue(ro, out Dictionary <int, XLCell> columnsCollection))
                {
                    for (int co = finalColumn; co >= columnStart && co > maxCo; co--)
                    {
                        if (columnsCollection.TryGetValue(co, out XLCell cell) &&
                            !cell.IsEmpty(options) &&
                            (predicate == null || predicate(cell)))
                        {
                            maxCo = co;
                        }
                    }
                }
            }
            return(maxCo);
        }
        public int FirstColumnUsed(int rowStart, int columnStart, int rowEnd, int columnEnd, XLCellsUsedOptions options,
                                   Func <IXLCell, Boolean> predicate = null)
        {
            int finalRow        = rowEnd > MaxRowUsed ? MaxRowUsed : rowEnd;
            int finalColumn     = columnEnd > MaxColumnUsed ? MaxColumnUsed : columnEnd;
            int firstColumnUsed = finalColumn;
            var found           = false;

            for (int ro = rowStart; ro <= finalRow; ro++)
            {
                if (rowsCollection.TryGetValue(ro, out Dictionary <Int32, XLCell> columnsCollection))
                {
                    for (int co = columnStart; co <= firstColumnUsed; co++)
                    {
                        if (columnsCollection.TryGetValue(co, out XLCell cell) &&
                            !cell.IsEmpty(options) &&
                            (predicate == null || predicate(cell)) &&
                            co <= firstColumnUsed)
                        {
                            firstColumnUsed = co;
                            found           = true;
                            break;
                        }
                    }
                }
            }

            return(found ? firstColumnUsed : 0);
        }
 IXLRangeRow IXLRange.LastRowUsed(XLCellsUsedOptions options, Func <IXLRangeRow, Boolean> predicate)
 {
     return(LastRowUsed(options, predicate));
 }
 IXLRangeRows IXLRange.RowsUsed(XLCellsUsedOptions options, Func <IXLRangeRow, Boolean> predicate)
 {
     return(RowsUsed(options, predicate));
 }
 IXLRangeColumns IXLRange.ColumnsUsed(XLCellsUsedOptions options, Func <IXLRangeColumn, Boolean> predicate)
 {
     return(ColumnsUsed(options, predicate));
 }