Hello!
I'm trying to understand how to work with single cell in merged cell range. When I use .getIsMerged(), it returns TRUE only for top-left cell in merged ranged for other cell in merged range FALSE is returned. How to get, that cell is in merge.
Official says that interface XMergeableCell has .getRowSpan and .getColumnSpan methods.
http://www.openoffice.org/api/docs/comm ... eCell.html
Object Xcell return error for these methods.
Oleg.
Thx for help!
interface XMergeableCell
interface XMergeableCell
Microsoft Windows XP, Apache OpenOffice 4.1.1
-
B Marcelly
- Volunteer
- Posts: 1160
- Joined: Mon Oct 08, 2007 1:26 am
- Location: France, Paris area
Re: interface XMergeableCell
Hi,
Interface com.sun.star.table.XMergeableCell exists for a cell in a Writer table.
Same remark for com.sun.star.table.XMergeableCellRange.
Calc uses interfaces com.sun.star.util.XMergeable
See Merging Cell Ranges into a Single Cell
See also method collapseToMergedArea() of interface com.sun.star.sheet.XSheetCellCursor.
Developer's Guide Cell Cursor, Cursor Movement.
Interface com.sun.star.table.XMergeableCell exists for a cell in a Writer table.
Same remark for com.sun.star.table.XMergeableCellRange.
Calc uses interfaces com.sun.star.util.XMergeable
See Merging Cell Ranges into a Single Cell
See also method collapseToMergedArea() of interface com.sun.star.sheet.XSheetCellCursor.
Developer's Guide Cell Cursor, Cursor Movement.
Bernard
OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
Re: interface XMergeableCell
Thx Bernard! It's first time I use Cursor and it takes time to understand XSheet.CreateCursorByRange().
I write in that way.
Is it possible not to check every xCell?
I write in that way.
Is it possible not to check every xCell?
Code: Select all
Sub Main
GlobalScope.BasicLibraries.LoadLibrary("MRILib")
'Dim d as Object 'thiscomponent
'Dim m as Object 'CellRange to Merge
'Dim x as Object 'Cell to Find IsMerged() = True
'Dim c as Object 'Cursor
'd=createUnoService ("com.sun.star.frame.Desktop")
d=thiscomponent
m=d.Sheets(0).getCellRangeByName("a1:x18") '(" : ")anyRange
m.merge(TRUE)
Dim column as Integer
Dim row as Long
Dim ForExit as Integer 'to exit Sub
for column% = 0 to 1024
'row = 0
for row = 0 to 1048576 '! That's too much and get time. Ex for Range "AC1:AD16"
x=d.Sheets(0).getCellByPosition(column,row)
if x.IsMerged() = TRUE then
CollapseToMergedArea(d,x,ForExit)
if ForExit = 2 then
exit Sub
end If
else
end if
next
next
End Sub
Function CollapseToMergedArea (d,x,Optional ForExit as Integer)
c=d.Sheets(0).createCursorByRange(x)'
c.collapseToMergedArea() = TRUE
ForExit = msgbox (c.AbsoluteName,1)
End Function
Microsoft Windows XP, Apache OpenOffice 4.1.1
Re: interface XMergeableCell
obj.getUniqueCellFormatRanges() returns an array of range collections.
Each range collection consists of cell ranges with exact same format attributes. Obj can be any single rectangle of cells. A sheet is a rectangle of cells.
Merging cells (the visible top-left cells of a merged range where getIsMerged() returns True) appear in separate range collections.
If you want to get rid of all merges on a sheet (which is the only thing I would do with that interface):
objSheet.merge(False) is enough.
Each range collection consists of cell ranges with exact same format attributes. Obj can be any single rectangle of cells. A sheet is a rectangle of cells.
Merging cells (the visible top-left cells of a merged range where getIsMerged() returns True) appear in separate range collections.
Code: Select all
a() = oSheet.getUniqueCellFormatRanges()
for each obj in a()
for i = 0 to obj.getCount()-1
oRange = obj.getByIndex(i)
if oRange.getIsMerged() then
x = getMergedArea(oRange)
etc, etc
else
exit for 'skip the for i loop because if this one is not merged the others aren't neither
endif
objSheet.merge(False) is enough.
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: interface XMergeableCell
Ok, I'm sorry for my ignorance. Villeroy, I understand you code logically. Sheets()->Sheet()->Range()->for_loop->if->...result->end. But due to lack of exerience ...
What is "obj"? I could not find clear information about it. Could you clear it, please. Just point me way and how to find "obj as .XSheetCellRangeContainer" appeared? All what I trying to do is step by step executing macros.
"getMergedArea" function is found at topic "Lets help Calc solve insert/delete row within merged range".
Thank you.
What is "obj"? I could not find clear information about it. Could you clear it, please. Just point me way and how to find "obj as .XSheetCellRangeContainer" appeared? All what I trying to do is step by step executing macros.
"getMergedArea" function is found at topic "Lets help Calc solve insert/delete row within merged range".
Code: Select all
Function getMergedArea (oRange)
oCursor = oRange.getSpreadsheet().createCursorByRange(oRange)
oCursor.collapseToMergedArea()
getMergedAreas = oCursor
End Function
Microsoft Windows XP, Apache OpenOffice 4.1.1