Writer\web HTML source macro to insert text

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
sam-sams-15
Posts: 8
Joined: Thu Feb 16, 2023 7:55 pm

Writer\web HTML source macro to insert text

Post by sam-sams-15 »

Hello everybody.
I'm trying to run a macro into Writer/web, so the document is in HTML SOURCE mode.
There I can write/edit html just fine but using my macro i can't insert text. This macro worked fine in Writer NORMAL MODE.

So my function simplified it's:

Code: Select all

sub p_text( dTxt as String)
	dim oCursor,vCursor as object
	
 	REM these lines  show ->error getViewCuror not found
 	'	vCursor = ThisComponent.CurrentController.getViewCursor()
	'	vCursor.getText.insertString(vCursor.getStart(), dTxt & CHR$(13), False) 
	REM These pass without error but doesnt write anything
	REM but i don't know if this text cursor is able to insert text without an specific anchor
		oCursor = thisComponent.getText.createTextCursor
		oCursor.getText.insertString(oCursor.getStart(), dTxt , False) 	
end Sub
I can't find any info in the particularities of this HTML SOURCE so if someone have some way to do it it'll make my day big time

Many thanks
Last edited by sam-sams-15 on Sun Mar 19, 2023 8:34 pm, edited 1 time in total.
OpenOffice 6.4.7.2
linux Mint 20
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: Writer\web HTML source macro to insert text

Post by JeJe »

Works for me on a new Writer/Web document - have you tried that.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
sam-sams-15
Posts: 8
Joined: Thu Feb 16, 2023 7:55 pm

Re: Writer\web HTML source macro to insert text

Post by sam-sams-15 »

No the macro doesn't work. The line:
ThisComponent.CurrentController.getViewCursor()
which allow to create the ViewCursor and so insert text into the document, rise an error. Somehow neither the TextCursor allow me to write anything. Perhaps ThisComponent or CurrentController don't apply to this mode/web.

To make some light: I call mode writer mode web, the document you create in libreoffice with the menu 'New-> HTML document', you can identify it with the 'writer/web' title in the window. In this new document there's the option to see the source (button {}). And it's there where i would like to write with my macro.

To go further, lets say, I paste pure code HTML from another editor into this writer/web. The document exported/saved from this mode will trash my html erasing my styles and adding a lot of garbage inside. But if I paste the code into the 'source view' then bingo! you can export and save the macro generated html.

For now, my workaround is to use the macro in normal plain text mode in the classic writer and 'without exporting or saving anything' copy the generated html and paste it into another editor to the save as html.
Hope this will make sense.
OpenOffice 6.4.7.2
linux Mint 20
mikele
Posts: 72
Joined: Wed Nov 21, 2018 11:11 am
Location: Germany

Re: Writer\web HTML source macro to insert text

Post by mikele »

Hello,
the error occurs only if you show the html source.
LibreOffice 5.4, 7.0, 7.2 on LinuxMint/Win10
sam-sams-15
Posts: 8
Joined: Thu Feb 16, 2023 7:55 pm

Re: Writer\web HTML source macro to insert text

Post by sam-sams-15 »

Well, no, the macro can't write nor in Web neither in source mode. My efforts to create a working Cursor (ViewCursor or Textcursor) failed. And anyway the web mode trash any html you write inside so only solution is source mode.
OpenOffice 6.4.7.2
linux Mint 20
Post Reply