Howto insert html styled text

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
djunges
Posts: 16
Joined: Tue Feb 19, 2008 4:54 pm

Howto insert html styled text

Post by djunges »

Hi,

im searching for a way to insert html formatex text into a document.
at the moment im using unoidl.com.sun.star.text.XTextRange setString function but it ignore html and style tags, inserts the tags instead

best regards
djunges
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Howto insert html styled text

Post by JeJe »

Have you tried pasting with the dispatch helper?

Code: Select all

	dim document   as object
	dim dispatcher as object
	document   = ThisComponent.CurrentController.Frame
	dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
	dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
djunges
Posts: 16
Joined: Tue Feb 19, 2008 4:54 pm

Re: Howto insert html styled text

Post by djunges »

Hi JeJe,

Thank you for you response.
This would be a possible solution, but I didn't want to use the Clipboard.
If pasting from the clipboard works then it should have a function that allows me to do the same but unfortunately I still can't find it.

I hope someone can help me

regards
djunges
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Howto insert html styled text

Post by JeJe »

You don't say the source of your html.

You can use gettransferable and settransferable to copy/paste content from an OO source
without using the clipboard

Example:

viewtopic.php?f=21&t=78814
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
djunges
Posts: 16
Joined: Tue Feb 19, 2008 4:54 pm

Re: Howto insert html styled text

Post by djunges »

thanks for you response,

The html source comes from database.
I have seen the settransferable, but i not found a way to create a XTransferable object and put the data into it. It seems to be used only to copy from one documento to another.

best regards
djunges
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Howto insert html styled text

Post by JeJe »

If no-one comes up with a better way you could save it to a file and then insert the file in the document.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
djunges
Posts: 16
Joined: Tue Feb 19, 2008 4:54 pm

Re: Howto insert html styled text

Post by djunges »

Hi JeJe

Thanks for you help.
To avoid using the Clipboard a saved the html data into a tmp file and then insert it with ".uno:InsertDoc"

regards
djunges
Post Reply