Copy a slide to other document : Impress

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

Copy a slide to other document : Impress

Post by HCL »

Is there any way to copy a slide between 2 Impress documents?

I tried in 3 ways, but failed.

===============================
- XDrawPageDuplicator.duplicate
copy a slide from doc1 to doc2.

- XDrawPage.add
copy all shapes from a slide on doc1 to a slide on doc2

- XTransferableSupplier
I couldn't find the way to make XTransferableSupplier instance on Impress.
OpenOffice 3.1 on Windows 10
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Copy a slide to other document : Impress

Post by JeJe »

Try the dispatch helper, add a switch to the paste document before the paste.

Code: Select all


dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SelectAll", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())

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

Re: Copy a slide to other document : Impress

Post by HCL »

Thank you for your reply, JeJe.

I tried as you said and succeeded to perform.

But motions are differ by states when perform "SelectAll".
It may be selected all slides, all shapes in a slide, or all text in a shape by this command.

So I must think to improve about this more.

Code: Select all

		public XComponentContext context;
		XMultiComponentFactory manager = context.getServiceManager();
		Object desktop_obj = manager.createInstanceWithContext(
				"com.sun.star.frame.Desktop", context);
		XDesktop desktop = UnoRuntime.queryInterface(XDesktop.class, desktop_obj);
		XMultiServiceFactory factory = UnoRuntime.queryInterface(XMultiServiceFactory.class, manager);
		
		Object helper_obj = factory.createInstance("com.sun.star.frame.DispatchHelper");
		XDispatchHelper helper = UnoRuntime.queryInterface(XDispatchHelper.class, helper_obj);
		
		XDispatchProvider provider = UnoRuntime.queryInterface(XDispatchProvider.class, desktop.getCurrentFrame());
		
		helper.executeDispatch(provider, ".uno:SelectAll", "", 0, new PropertyValue[] {});
OpenOffice 3.1 on Windows 10
Post Reply