[Solved] Copy writer editing document

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
HCL
Posts: 22
Joined: Thu Jul 22, 2021 3:55 am

[Solved] Copy writer editing document

Post by HCL »

How to copy(or duplicate) a writer document?
I want to copy a editing writer document.

I found a way to use "XDocumentInsertable.insertDocumentFromURL".

But it just copy saved document.
It mean that this method can't copy editing document that are not saved.
Last edited by robleyd on Sat Jul 24, 2021 5:02 am, edited 2 times in total.
Reason: Add green tick
OpenOffice 3.1 on Windows 10
JeJe
Volunteer
Posts: 2755
Joined: Wed Mar 09, 2016 2:40 pm

Re: Copy writer editing document

Post by JeJe »

Is this what you're after:

https://www.openoffice.org/api/docs/com ... plier.html

Code: Select all

'copy the selection to a variable
trans= thiscomponent.currentcontroller.getTransferable

'insert the copied selection
thiscomponent.currentcontroller.setTransferable(trans)

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
HCL
Posts: 22
Joined: Thu Jul 22, 2021 3:55 am

[Solved] Copy writer editing document

Post by HCL »

Thank you for your reply.

I could do I wanted by your advice.

And
https://blog.oio.de/2010/10/27/copy-and ... e-org-api/

===============================

Code: Select all

		XTextDocument xdoc1; // Source to be copied
		XTextDocument xdoc2; // Target to copy

		XTransferableSupplier sup1 = UnoRuntime.queryInterface(XTransferableSupplier.class, xdoc1.getCurrentController());
		XTransferableSupplier sup2 = UnoRuntime.queryInterface(XTransferableSupplier.class, xdoc2.getCurrentController());
		
		// Select target texts to be copied
		XSelectionSupplier xSelectionSupplier = UnoRuntime.queryInterface(XSelectionSupplier.class, xdoc1.getCurrentController());
		xSelectionSupplier.select(xdoc1.getText());
		
		sup2.insertTransferable(sup1.getTransferable());
OpenOffice 3.1 on Windows 10
Post Reply