[Solved] How to get range of merged cells

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
VBandOoffice
Posts: 33
Joined: Tue Jul 31, 2018 10:11 am

[Solved] How to get range of merged cells

Post by VBandOoffice »

Hi all,
I need to know, weather some cells of a spreadsheet are merged together or not.
If I define a range and look to isMerged or use getIsMerged, then I get TRUE, even if only the first two cells from ten cells are merged together.
Only if there are no cells at all merged, isMerged will be read FALSE.

Do anyone know about this - and how to work around? I'm using LibreOffice 6.1.4 and Windows7

Best regards,
VBandOoffice
Last edited by VBandOoffice on Tue Jan 22, 2019 3:46 pm, edited 1 time in total.
LibreOffice 7.5, Windows 10, VB.net 2019, C#
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: How to get range of merged cells

Post by Lupp »

On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
VBandOoffice
Posts: 33
Joined: Tue Jul 31, 2018 10:11 am

Re: How to get range of merged cells

Post by VBandOoffice »

Hello Lupp,

with the code from Villeroy (Sub fillMergedAreas(oRange, oRanges)) I only get all StartCells of merged cells correctly, but the range is not matching the real merged range.
If there are some unmerged cells between the merged ranges, I will not detect them.

Some Ideas why? - And how to get the real merged range?

Best regards,
VBandOoffice
LibreOffice 7.5, Windows 10, VB.net 2019, C#
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to get range of merged cells

Post by Villeroy »

In the attached file (selectMerged.ods) you find a function that returns the merged region of a start cell.
In fact the macro in that document selects all the regions. The code snippet in the other posting is faster since it does not do that.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: How to get range of merged cells

Post by JeJe »

My oops.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
VBandOoffice
Posts: 33
Joined: Tue Jul 31, 2018 10:11 am

Re: How to get range of merged cells

Post by VBandOoffice »

Hi all,

it works!

Thank you Villeroy!

Best regards to all,
VBandOoffice
LibreOffice 7.5, Windows 10, VB.net 2019, C#
Post Reply