Calc merged cell macro returns false - bug or intentional?

When getting the merged properties of a cell (isMerged), only the first cell returns True. Not sure if this is a bug that should be reported or if there is a way around this.

Libreoffice on CentOS


         |     A         |      B         |
|   1    |  Merged Cell                   |
|   2    |  Normal       |   Normal       |

The spreadsheet generated the following results:

getCellRangeByName("$A$1").getIsMerged -> True
getCellRangeByName("$A$2").getIsMerged -> False
getCellRangeByName("$B$1").getIsMerged -> False  (why??!!)
getCellRangeByName("$B$2").getIsMerged -> False

Any hacks to get around this?

Hello @UserRyan. Thanks for asking.

I think this is expected behavior, cause IsMerged property is set to True only for the cell that remains visible after merging - first cell of the range. Other cells are just hidden under this cell with their IsMerged property set to False. If you want to get the whole merged range, you can use Cursor for this purpose.

Assume you find that cell with property IsMerged set to True is cell A1 on the first sheet of document:

oSheet = ThisComponent.GetSheets().GetByIndex(0)    
oMergedCell = oSheet.getCellRangeByName("A1")
oCursor = oSheet.CreateCursorByRange(oMergedCell)

So now oCursor range is $Sheet1.$A$1:$B$1