Hallo Cor

Cor Nouws wrote:
Hi *

I want to know the width and height of the cell in a Writer table.
I wanted the same thing some time ago to put pictures with the right dimensions in texttable cells. Iit can be done but only when the hight of the rows are set to a fixed dimension. The problem with the disapearing TableColumnSeparators when cells are merged is resolved with making a new index out of the name off the cell. For Finding the hight of merged cells is jumbed around with the cursor and uses the cells around the merged cell to find out the hight off the merged cell. Please find my basic code, you must understand fFlamish no? :-) so mi comments are readable for you.

Hope it  Helps
Fernand

   oText = oDocument.text
    oViewCursor = oDocument.getCurrentController().getViewCursor()
   If Not isEmpty(oViewCursor.TextTable) then  ' Cursor is in een Tabel
   sFrameofTabel = "TABEL"
   inFRameofTabel = true
   RasterofCursor = False
   Twidth = oViewCursor.TextTable.width
   TTotalpercent = oViewCursor.TextTable.TableColumnRelativeSum
   startcell = oViewCursor.cell.cellname
   Kindex = asc(left(oViewCursor.cell.cellname,1))-65
   Rindex = int(mid(oViewCursor.cell.cellname,2,2))-1
   CurRow = oViewCursor.texttable.rows.getbyindex(Rindex)
   if CurRow.IsAutoHeight = True then
msgbox "De ROWhooghte moet FIXED zijn !!!!!" & chr(13) & "Eerst aanpassen, dan pas kan je verder"
   exit sub
   end if
if oViewCursor.texttable.Horiorient = 6 then msgbox " De Table mag niet AUTOMATISCH gealigneerd zijn" & chr(13) & "wordt nu automatisch aangepast naar ""center"" !!"
    oViewCursor.texttable.Horiorient = 2
   end if

' welke cell ?? startcellname = oViewCursor.cell.cellname startrow = int(mid(startcellname,2,2))
   if  oViewCursor.cell.VertOrient <> 2 then
msgbox "Cursor staat niet in de HOOGTE gecentreerd" & chr(13) & "wordt nu automatisch aangepast !!"
   oViewCursor.cell.VertOrient = 2
   end if
' do while int(mid(oViewCursor.cell.cellname,2,2)) = startrow ' we blijven in dezelfde rij oViewcursor.goDOWN(1,false) ' de tabel MOET in een FRame zitten anders problemen bij de onderste rij !!!!! if isEmpty(oViewCursor.TextTable) then
         startcellpos = "ONDER"
         oViewcursor.goUP(1,false)
        end if
if startcellpos = "ONDER" then
    'eerst terug naar startcell
    otext = oviewcursor.texttable.getcellbyname(startcellname,true).text
otabelCursor = oText.createTextCursor() oViewcursor.gotorange(otabelCursor,false) laatsterow = oViewCursor.TextTable.rows.count if laatsterow = int(mid(oViewCursor.cell.cellname,2,2)) then ' cell is één row hoog
    iFotH = oViewCursor.texttable.rows.getbyindex(Rindex).height
    else
       for i= 0 to laatsterow - int(mid(oViewCursor.cell.cellname,2,2))
iFotH = iFotH + oViewCursor.texttable.rows.getbyindex(Rindex+ i ).height
    next i
end if else 'cell boven of midden
    ' eerst terug naar de startcell
    otext =  oviewcursor.texttable.getcellbyname(startcellname,true).text
otabelCursor = oText.createTextCursor()
    oViewcursor.gotorange(otabelCursor,false)
    startrow = int(mid(oViewCursor.cell.cellname,2,2))
            oViewcursor.goDOWN(1,false)
           volgenderow = int(mid(oViewCursor.cell.cellname,2,2))
if isEmpty(oViewCursor.TextTable) then 'terug naar binnen de tabel
        oViewcursor.goUP(1,false)
        end if
     ' terug naar de startcell
    otext = oviewcursor.texttable.getcellbyname(startcellname,true).text
    otabelCursor = oText.createTextCursor()
    oViewcursor.gotorange(otabelCursor,false)
    for i= 1 to volgenderow - startrow
iFotH = iFotH + oViewCursor.texttable.rows.getbyindex(Rindex + i-1 ).height next i endif tabstops = CurRow.TableColumnSeparators() if uBound(tabstops)< 0 then
   iFotW = tWidth
else if kindex = 0 then
       iFotW = (twidth * tabstops(Kindex).position/TTotalpercent)
       elseif kindex -1 = ubound(tabstops) then
iFotW = twidth - (twidth * tabstops(Kindex-1).position/TTotalpercent) else iFotW = (twidth * tabstops(Kindex).position/TTotalpercent) - (twidth * tabstops(Kindex-1).position/TTotalpercent)
       endif
   end if


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




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

Reply via email to