예제 #1
0
        private MoveData[] ScanRange(int groupBy)
        {
            Sheet.SuspendEvents();
            IXLRangeRow     lastRow    = null;
            string          prevVal    = null;
            int             groupStart = 0;
            List <MoveData> groups     = new List <MoveData>();

            using (var rows = _range.Rows())
            {
                foreach (var row in rows)
                {
                    lastRow = row;

                    var val          = row.Cell(groupBy).GetString();
                    var isSummaryRow = row.IsSummary();

                    if (string.IsNullOrEmpty(val) && !isSummaryRow)
                    {
                        if (groupStart > 0)
                        {
                            groups.Add(CreateMoveTask(groupBy, prevVal, _range.Cell(groupStart, 1), row.RowAbove().Unsubscribed().LastCell(), RangeType.DataRange));
                        }
                        groups.Add(CreateMoveTask(groupBy, "", row.FirstCell(), row.LastCell(), RangeType.HeaderRow));
                        prevVal    = null;
                        groupStart = 0;
                        continue;
                    }

                    if (val != prevVal)
                    {
                        if (groupStart > 0)
                        {
                            groups.Add(CreateMoveTask(groupBy, prevVal, _range.Cell(groupStart, 1), row.RowAbove().Unsubscribed().LastCell(), RangeType.DataRange));
                        }
                        prevVal    = val;
                        groupStart = !isSummaryRow?row.RangeAddress.Relative(_range.RangeAddress).FirstAddress.RowNumber : 0;
                    }
                    if (isSummaryRow)
                    {
                        var moveData = new MoveData(row.RangeAddress, RangeType.SummaryRow, "", Sheet.Row(row.RowNumber()).Unsubscribed().OutlineLevel);
                        moveData.PageBreak = Sheet.PageSetup.RowBreaks.Any(x => row.RowNumber() - (_summaryAbove ? 1 : 0) == x);
                        groups.Add(moveData);
                    }
                }
                if (lastRow != null && groupStart > 0)
                {
                    using (var groupRng = _range.Range(_range.Cell(groupStart, 1), lastRow.LastCell()))
                        groups.Add(new MoveData(groupRng.RangeAddress, RangeType.DataRange, prevVal, Sheet.Row(groupStart).Unsubscribed().OutlineLevel)
                        {
                            GroupColumn = groupBy
                        });
                }
            }

            Sheet.ResumeEvents();
            return(groups.ToArray());
        }
예제 #2
0
 public object GetValue(IXLRangeRow row)
 {
     if (row.LastCell().TryGetValue(out int key))
     {
         if (key >= 0 && key < _items.Length)
         {
             return(_items[key]);
         }
     }
     return(null);
 }
예제 #3
0
        private MoveData[] ScanRange(int groupBy)
        {
            IXLRangeRow     lastRow    = null;
            string          prevVal    = null;
            int             groupStart = 0;
            List <MoveData> groups     = new List <MoveData>();

            var rows = _range.Rows();

            foreach (var row in rows)
            {
                lastRow = row;

                var val          = row.Cell(groupBy).GetString();
                var isSummaryRow = row.IsSummary();

                if (string.IsNullOrEmpty(val) && !isSummaryRow)
                {
                    if (groupStart > 0)
                    {
                        groups.Add(CreateMoveTask(groupBy, prevVal, _range.Cell(groupStart, 1), row.RowAbove().LastCell(), RangeType.DataRange));
                    }
                    groups.Add(CreateMoveTask(groupBy, "", row.FirstCell(), row.LastCell(), RangeType.HeaderRow));
                    prevVal    = null;
                    groupStart = 0;
                    continue;
                }

                if (val != prevVal)
                {
                    if (groupStart > 0)
                    {
                        groups.Add(CreateMoveTask(groupBy, prevVal, _range.Cell(groupStart, 1), row.RowAbove().LastCell(), RangeType.DataRange));
                    }
                    prevVal    = val;
                    groupStart = !isSummaryRow?row.RangeAddress.Relative(_range.RangeAddress).FirstAddress.RowNumber : 0;
                }
                if (isSummaryRow)
                {
                    var moveData = CreateMoveTask(groupBy, "", row.FirstCell(), row.LastCell(), RangeType.SummaryRow);
                    moveData.PageBreak = Sheet.PageSetup.RowBreaks.Any(x => row.RowNumber() - (_summaryAbove ? 1 : 0) == x);
                    groups.Add(moveData);
                }
            }
            if (lastRow != null && groupStart > 0)
            {
                groups.Add(CreateMoveTask(groupBy, prevVal, _range.Cell(groupStart, 1), lastRow.LastCell(), RangeType.DataRange));
            }

            return(groups.ToArray());
        }