You can do it without the TextFrame, which may be cleaner, if not simpler.
Code: Select all
oCell = objTabelle.getCellByName("A1")
oCellText = oCell.Text
oCursor = oCellText.createTextCursor()
oCursor.setString("Click here")
oCursor.gotoStart(False)
oCursor.gotoEnd(True)
oCursor.HyperLinkURL = "http://user.services.openoffice.org/en/forum/"
It is probably worth noting something I discovered here; the following works in a Calc cell:
Code: Select all
Sub MakeForumLinkInA1
Dim oDoc As Object
Dim oSheet As Object
Dim oCell As Object
Dim oCursor As Object
Dim oCellText
Dim tField
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
oCell = oSheet.getCellRangeByName("A1")
tField = oDoc.createInstance( "com.sun.star.text.textfield.URL" )
tField.Representation = "Click here"
tField.URL = "http://user.services.openoffice.org/en/forum/"
oCellText = oCell.getText()
oCursor = oCellText.createTextCursor()
oCursor.gotoStart(False)
oCellText.insertTextContent(oCursor,tField,False)
End Sub
But it seems you
cannot do insertTextContent with a com.sun.star.text.textfield.URL either into a Writer table or into the main text, and conversely, there is no HyperLinkURL property on an XTextCursor in the text of a Calc cell. Thus the Calc and Writer cases need to be handled differently, though you might be able to insert a com.sun.star.text.TextFrame into a Calc cell (I haven't tried that yet).
Edit: insertTextContent in aCalc cell doesn't seem to work with a TextFrame. |