Writer get Cell Paragraph width of Texttable for current Cell, Paragraph indention

Hello Together,

i try to make a macro that inserts a picture in the current Texttable Cell as link. Therefore I want to limit the width of the picture to Cell width or better to the width of the Cell Paragraph. For the width of the Cell/Paragraph I suggest the following solution. See the comments in source code. But I can’t find the value for Paragraph indention. How can I get it?

sub wnCellwidth
	oWNDoc = ThisComponent
	oWNCursor=ThisComponent.CurrentController.getViewCursor()
	'Check if Cursor is in TextTable
	if not(isEmpty(oWNCursor.TextTable)) then
		oWNCell = oWNCursor.Cell
		msgbox "Cell Width: " & funWNCellWidth(oWNDoc, oWNCell)
	else
		msgbox "Not in TextTable, do nothing!"
	end if 
end sub

function funWNCellWidth(oWNDoc, oWNCell) as double
  	oWNCursor = oWNCell.createTextCursor()
  	oWNViewCursor = oWNDoc.getCurrentController.getViewCursor
	'Store Viewcursor Position to restore it later
	oWNcursorPrevPos=oWNViewCursor.Start
	'Store ParaAdjust for Restore
  	'oWNParaAdjustorg=oWNCursor.paraAdjust
	'Set ParagraphAdjust to Left got to Start to find the left Position
	'of the Cell
	'oWNCursor.paraAdjust = com.sun.star.style.ParagraphAdjust.LEFT
    oWNCursor.gotoStartOfParagraph(false)
    oWNViewCursor.gotoRange(oWNCursor, false)
    lWNLeft = oWNViewCursor.getPosition().x
	'Set ParagraphAdjust to Right got to End to find the left Position
	'of the Cell
	'oWNCursor.paraAdjust = com.sun.star.style.ParagraphAdjust.RIGHT
    oWNCursor.gotoEndOfParagraph(false)
    oWNViewCursor.gotoRange(oWNCursor, false)
    lWNRight = oWNViewCursor.getPosition().x
    'Reset paraAdjust
    'oWNCursor.paraAdjust=oWNParaAdjustorg
    'Calculate and Return the Cell Width
    'if you replace the next line, with
    '	funWNCellWidth = Cdbl(lWNRight - lWNLeft + 2*oWNCell.Borderdistance)
    'you will get the Cell width
    funWNCellWidth = Cdbl(lWNRight - lWNLeft)
    'Restore the original Cell Cursorposition
	'oWNViewCursor.goToRange(oWNcursorPrevPos, false)
end function

Best Regards

Wolfgang

I’m using libreoffice 7.6.6 on Windows and 24.2 on Manjaro Linux.

Try

nindent = oWNViewCursor.ParaLeftMargin
nflindent = oWNViewCursor.ParaFirstLineIndent

to get indend and first line indent in 1/1000 cm

you can also read the values from cellstyle

    sStyle = oWNViewCursor.ParaStyleName
    oStyle =  thisComponent.Stylefamilies.ParagraphStyles.getbyname(sStyle)
    nindent = oStyle.ParaLeftMargin
    nflindent = oStyle.ParaFirstLineIndent
1 Like

Thank you, that works.

Best Regards
Wolfgang