Hi,
In a python macro I create a new doc from a template. I'd like now to copy the whole text of my current document (including styles) and paste it at the end of my new created document.
For now, I only can select text and paste it but I loose the formatting style. Is there a way to make it ?
[Solved] Python copy text + style from a document to anothe
[Solved] Python copy text + style from a document to anothe
Last edited by Bastien on Thu Oct 01, 2015 3:49 pm, edited 2 times in total.
LibreOffice 6.2.3.2 on Ubuntu 19.04
Re: Python select text including style from a document to an
Record a copy&paste operation in Basic, change the syntax to Python.
Otherwise, there is an XTransferable interface http://www.openoffice.org/api/docs/comm ... rable.html
Otherwise, there is an XTransferable interface http://www.openoffice.org/api/docs/comm ... rable.html
Last edited by RoryOF on Thu Oct 01, 2015 12:08 pm, edited 1 time in total.
Reason: Corrected significant typo in message [RoryOF, Moderator]
Reason: Corrected significant typo in message [RoryOF, Moderator]
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Python select text including style from a document to an
What do you mean by record a copy&paste operation in Basic? I can't see this function.
The Xtransferable interface seems to be really powerful but it is quite abstract to me. Could you suggest me a way to use it (preferably in python)?
The Xtransferable interface seems to be really powerful but it is quite abstract to me. Could you suggest me a way to use it (preferably in python)?
LibreOffice 6.2.3.2 on Ubuntu 19.04
Re: Python select text including style from a document to an
Ah, LibreOffice. menu:Tools>Options>Advanced>Enable Macro recording
Tools>Macros>Record macro ... (a new toolbar pops up)
Copy some cells, paste some cells, stop the macro recorder, save and edit the macro which is a dispatch macro. Dispatch macros simulate selections and clicks in the user interface. It is easy to convert dispatch macros from Basic to Python. ThisComponent --> XSCRIPTCONTEXT.getDocument(), change the blocks to Pyhon indentation blocks.
search.php?keywords=XTransferable&terms ... mit=Search
Tools>Macros>Record macro ... (a new toolbar pops up)
Copy some cells, paste some cells, stop the macro recorder, save and edit the macro which is a dispatch macro. Dispatch macros simulate selections and clicks in the user interface. It is easy to convert dispatch macros from Basic to Python. ThisComponent --> XSCRIPTCONTEXT.getDocument(), change the blocks to Pyhon indentation blocks.
search.php?keywords=XTransferable&terms ... mit=Search
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Python select text including style from a document to an
Very quick, very easy indeed using the dispatcher.
Here is the code doing that:
It surely would have been smarter using Xtransferable but for now, it works.
Here is the code doing that:
Code: Select all
def copy_all():
document = XSCRIPTCONTEXT.getDocument()
ctx = uno.getComponentContext()
sm = ctx.ServiceManager
dispatcher = sm.createInstanceWithContext("com.sun.star.frame.DispatchHelper", ctx)
frame = document.CurrentController.Frame
dispatcher.executeDispatch(frame, ".uno:SelectAll", "", 0, ())
dispatcher.executeDispatch(frame, ".uno:Copy", "", 0, ())
LibreOffice 6.2.3.2 on Ubuntu 19.04
Re: [Solved] Python copy text + style from a document to ano
Search Xtransferable in this forum:
viewtopic.php?f=20&t=56753&p=249848&hil ... le#p249848
viewtopic.php?f=20&t=56753&p=249848&hil ... le#p249848
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice