@@ -304,12 +304,25 @@ public SubtotalGroup[] ScanForGroups(int groupBy)
304
304
305
305
foreach ( var moveData in grRanges )
306
306
{
307
- if ( moveData . Type == RangeType . DataRange )
307
+ if ( moveData . Type != RangeType . DataRange ) continue ;
308
+
309
+ var groupRng = Sheet . Range ( moveData . SourceAddress ) ;
310
+
311
+ var cuttingGroups = _groups . Where ( g => moveData . SourceAddress . Contains ( g . Range . RangeAddress . LastAddress ) ) . ToArray ( ) ;
312
+ if ( cuttingGroups . Any ( ) )
308
313
{
309
- var groupRng = Sheet . Range ( moveData . SourceAddress ) ;
310
- var gr = new SubtotalGroup ( level , groupBy , moveData . GroupTitle , groupRng , null , false ) ;
311
- result . Add ( gr ) ;
314
+ var startAddress = moveData . SourceAddress . FirstAddress ;
315
+ foreach ( var g in cuttingGroups )
316
+ {
317
+ groupRng = Sheet . Range ( startAddress , g . Range . RangeAddress . LastAddress ) ;
318
+ result . Add ( new SubtotalGroup ( level , groupBy , moveData . GroupTitle , groupRng , null , false ) ) ;
319
+ startAddress = g . Range . LastCell ( ) . WorksheetRow ( ) . RowBelow ( )
320
+ . Cell ( startAddress . ColumnNumber ) . Address ;
321
+ }
322
+ groupRng = Sheet . Range ( startAddress , moveData . SourceAddress . LastAddress ) ;
312
323
}
324
+
325
+ result . Add ( new SubtotalGroup ( level , groupBy , moveData . GroupTitle , groupRng , null , false ) ) ;
313
326
}
314
327
315
328
_groups . AddRange ( result ) ;
0 commit comments