Code: Select all
.. This is the content of
( ) the paragraph which might take
\/ more lines and exceed the height
of the icon on the left.
But I am stuck when trying to insert a graphic into a table cell. Inserting an image into a normal paragraph is working (I used code from Andrew Pitonyak Macro book).
Code: Select all
oDoc = ThisComponent
' Create a table and attach/insert it at the current cursor position
vViewCursor = oDoc.getCurrentController().getViewCursor()
oTable = oDoc.createInstance("com.sun.star.text.TextTable")
oTable.initialize(1, 2)
oDoc.getText.insertTextContent( vViewCursor, oTable, False )
' I can manipulate the table (Text content of the right cell, borders ...)
' Create an Image with the method from Andrew's book
oImage = oDoc.createInstance("com.sun.star.text.GraphicObject")
With oImage
.GraphicURL = ConvertToURL("C:\temp\note.png")
.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
.Width = 3000
.Height = 3000
End With
' I get quite a lot of exceptions when I inspect the graphic object with Xray
' but that's like that in normal paragraphs and the graphic is inserted without problem
' create a text cursor in the left cell
oCursor = oTable.getCellByPosition(0,0).createTextCursor()
' Xray shows that the created cursor has all the typical cursor properties and methods
oDoc.getText.insertTextContent( oCursor, oImage, False ) ' RUNTIME ERROR HERE
Probably because the table is not part of the normal ThisComponent.getText stream. Seems like I need a "text something" from the table cell for that I can call the insertTextContent method.
The API says about the XText or XSimpleText interface that defines this insert method:
Clearly there is TEXT in a table cell! But how do I get access to this object?is the main interface for a distinct text unit, i.e. the main text of a document, the text for headers and footers or for single cells of a table.
oTable.getCellByPosition(0,0).iWantTheText().insertTextContent(oCursor,oImage,False) ??
Any ideas? Thank you ...