table have 2 columns.
First column have 10 cells(1 cell =1 row)
Second column have 2 cells,upper cell height 6 rows,bottom cell height 4 rows.
How to get height upper and bottom cells in program on basic?,
how to get content upper and bottom cells in program on basic?
May be so?
Sub getHeigthOfMergedCells
Dim oSheet As Variant
Dim nCount As Long
Dim oCellFormatRanges As Variant
Dim oEnum As Variant
Dim oCell As Variant
Dim oCursor As Variant
Dim aRes() As String
oSheet = ThisComponent.getSheets().getByIndex(0)
oCellFormatRanges = oSheet.getCellFormatRanges()
oEnum = oCellFormatRanges.createEnumeration()
Do While oEnum.hasMoreElements()
oCell = oEnum.nextElement()
If oCell.getIsMerged() Then
nCount = UBound(aRes())+1
ReDim Preserve aRes(nCount)
oCursor = oSheet.createCursorByRange(oCell)
oCursor.collapseToMergedArea()
aRes(nCount) = "Cell " + oCell.AbsoluteName + "(" _
+ oCursor.AbsoluteName +") has Height=" _
+ oCursor.Size.Height + ", Width=" _
+ oCursor.Size.Width + " and Value='" _
+ oCell.getCellByPosition(0,0).getString() + "'"
EndIf
Loop
If LBound(aRes()) > UBound(aRes()) Then
MsgBox("No merged cells...")
Else
MsgBox("Found merged cells:"+Chr(10)+Join(aRes,Chr(10)))
EndIf
End Sub
NB. This Size (Height & Width) in 1/100 mm. If you want get it in “cells”, use oCursor.getRows().getCount() and oCursor.getColumns().getCount()
when test?get message oCell.getString() (-absent ???not found)
Host archlinux x86_64,libreoffice 3.6.4-1 file.rtf http://exfile.ru/download/389963
read in Calc
Thank you!
Yes, it was a typo. Not oCell.getString(), but oCell.getCellByPosition(0,0).getString(). Fixed.
You have only 3 merged cells in this file ($R$39:$S$39,$R$40:$S$41 and $R$42:$S$42)