Merge and Unmerge

Method

Merge range start at (2,1) and the number of rows is 3, number of columns is 4:
grid.MergeRange(new ReoGridRange(2, 1, 3, 4));

22_2.png

Unmerge any cells in range:
grid.UnmergeRange(new ReoGridRange(0, 0, 10, 10));

Action

Merge range start at (0,0) and the number of rows is 4, number of columns is 6:
grid.DoAction(new RGMergeRangeAction(new ReoGridRange(0, 0, 4, 6)));

Unmerge any cells range:
grid.DoAction(new RGUnmergeRangeAction(new ReoGridRange(0, 0, 4, 6)));

Run Script

Merge a specified range by script execution:
grid.mergeRange(new Range(0, 0, 4, 6));
grid.unmergeRange(new Range(0, 0, 4, 6));

or apply to selected range:
grid.mergeRange(grid.selection);
grid.unmergeRange(grid.selection);

Note

UnmergeRange method will find and unmerge all merged cells in a specified range, the merged cells A, B and C as below will be unmerged together if the red range is the target.
9.png

Merged Cells

Check for merged cell

Only the first left-top cell in a merged range is the merged cell.
10.png

To check whether a cell is merged cell, use method IsMergedCell of control:
bool isMergedCell = grid.IsMergedCell(2, 1);      // false
bool isMergedCell = grid.IsMergedCell(2, 2);      // true
bool isMergedCell = grid.IsMergedCell(2, 3);      // false

Rowspan & Colspan

A merged cell has two properties that is used to determine that how many cells are merged:
11.png
The cell in the position 2:1 is a merged cell, its rowspan is 4 and colspan is 3.

By getting instance of the cell to get more information:
Get rowspan and colspan:
var rowspan = cell.GetRowspan();   // number of rowspan
var colspan = cell.GetColspan();   // number of colspan

Property IsMergedCell check whether this cell is merged cell:
bool isMergedCell = cell.IsMergedCell;

Find out merged cell

ReoGrid provides a method called GetMergedCellOfRange which is used to find merged cell out from a specified range.
12.png
ReoGridCell output = grid.GetMergedCellOfRange(input);

Valid and invalid cells

Cells merged by others cell will become invalid, an invalid cell cannot be set any data and styles. Red range is a merged cell, the cells labeled 'No' are all invalid.
19.png
There is a method of control named IsValidCell that is used to check whether a cell is valid.
grid.IsValidCell(2, 2);      // true
grid.IsValidCell(2, 3);      // false

Check for whole merged cell

There is a method used to check and get a whole cell if part of one is given.
56.png
ReoGridRange outputRange = grid.CheckMergedRange(inputRange);

RangeIntersectionException

Range to be merged may intersect with other merged cells, try to merge intersected range will cause RangeIntersectionException.
20.png
User-code should handle this exception and cancel current operation.
21.png
Method CheckIntersectedMergingRange used to check whether any merged cell contained in specified range. This method is useful to avoid the exception above.
ReoGridRange outputRange = grid.CheckIntersectedMergingRange(inputRange);

If outputRange.IsEmpty is true, that means the inputRange is safe. There is another method to do same thing:
bool rs = grid.HasIntersectedMergingRange(inputRange);

Next: Data Format

Last edited Dec 24, 2013 at 8:09 AM by unvell, version 12