Hi *

I want to know the width and height of the cell in a Writer table.

The piece of code (see below) should give this info (not complete for all kind of situations reg. table width, but that's not the problem).

Relative small problem: when a row is autoheight and I set that property to false in the code, the height still is 0.

Bigger problem: if any cell of the table is merged or splitt, there is, AFAIK, no way to get the width of columns, cause the property TableColumnSeparators of the table is not existing / available any more.

Any ideas on this?

Many thanks,
Cor

==== code

Sub GiveSizeOfThisCell
' 22-9-08
 Dim sCellName$, sBookmarkName$, sTableName$
 Dim iColumn%, iRowNr%  ' index of the column and row
 Dim nRowNr$
 Dim oText, oCursor, oTable, oCell, oRow, oColumn, oTblColSeps
 Dim lTableWith&, lColumnLeftPerc&, lColumnRightPerc&,
 Dim lColumnWidth&, lRowHeight&
        
  sBookmarkName = "InsertPicture3"
    sTableName = "Tabel2"
    sCellName =
ThisComponent.Bookmarks.getByName(sBookmarkName).getAnchor.getStart.Cell.CellName
    oTable = ThisComponent.TextTables.getByName(sTableName)
    oCell = oTable.getCellByName(sCellName)
    iColumn = ( Asc(Left(oCell.CellName, 1)) -65)

    'oColumn = oTable.Columns.getByIndex( iColumn)
    ' does not work
    ' one cannot get the column via API, although it is there in the UI
    ' width is found in object TableSeparators
                
    ' set table with properties,
    ' HoriOrient (auto) of 6 leads to wrong value
    lTableWith = GiveMyPageTextWidth  ' other routine returning this
    oTable.Width = lTableWith
    oTable.HoriOrient = 3

    'this does not work in tables with merged cells!
    oTblColSeps = oTable.TableColumnSeparators
    ' iColumn = index, left separator position (in percent) = index - 1

    If iColumn = 0 then
      lColumnLeftPerc = 0
      lColumnRightPerc = oTblColSeps(iColumn).Position
    Else
      lColumnLeftPerc = oTblColSeps(iColumn-1).Position
      lColumnRightPerc = oTblColSeps(iColumn).Position
    End If
    lColumnWidth = lTableWith *(lColumnRightPerc - lColumnLeftPerc) /10000

    iRowNr = Cint(Right(oCell.CellName, len(oCell.CellName)-1)) -1
    oRow = oTable.Rows.getByIndex(iRowNr)

    If oRow.IsAutoHeight = TRUE Then
      oRow.IsAutoHeight = FALSE
      ' does not set the property height to the actual value :-(
      lRowHeight = oRow.Height
      oRow.IsAutoHeight = TRUE
    Else
      lRowHeight = oRow.Height
    End If
    msgbox "h x b = " & oRow.Height & " x " & lColumnWidth

End Sub


--
"The Year of 3" -2008- "Het jaar van 3"

Cor Nouws - Arnhem - Netherlands
  > marketing contact - http://nl.OpenOffice.org
  > Zeker van OpenOffice.org - www.nouenoff.nl



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to