[Solved] Duplicate TextContent to another Doc

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
wanglong
Posts: 51
Joined: Fri Sep 09, 2022 10:57 am
Location: Beijing,China

[Solved] Duplicate TextContent to another Doc

Post by wanglong »

Hello everyone!
When I try to duplicate some textcontent from one Doc to another with below code,

Code: Select all

// Loop through all paragraphs of the document
        while ( xParagraphEnumeration.hasMoreElements() ) {
            xTextElement = (com.sun.star.text.XTextContent)
                    UnoRuntime.queryInterface(
                            com.sun.star.text.XTextContent.class,
                            xParagraphEnumeration.nextElement());
            try
            {
                outText.insertTextContent(outText.getEnd(),xTextElement,false);
            }
            catch ( java.lang.Exception e )
            {
                e.printStackTrace();
            }
        }
I catched some RuntimeException like this,

Code: Select all

com.sun.star.uno.RuntimeException: 
	at com.sun.star.lib.uno.environments.remote.Job.remoteUnoRequestRaisedException(Job.java:173)
	at com.sun.star.lib.uno.environments.remote.Job.execute(Job.java:139)
	at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:334)
	at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:303)
	at com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java:87)
	at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java:636)
	at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java:146)
	at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java:128)
	at com.sun.proxy.$Proxy9.insertTextContent(Unknown Source)
	at TemplateConfigurator.text.ParseUITextDocument.readParagraph(ParseUITextDocument.java:60)
I found this xTextElement can't be inserted to another Doc.But if I create a new TextContent like TextField with getInstance(),the new instance could be inserted to the Doc where created it.
So,I want to known how to duplicate an old TextContent already existed in Text Doc?

Thanks in advance.
Last edited by MrProgrammer on Mon Nov 07, 2022 3:57 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
Libre Office 7.6 on Windows 11.
JeJe
Volunteer
Posts: 2906
Joined: Wed Mar 09, 2016 2:40 pm

Re: duplicate TextContent to another Doc

Post by JeJe »

You can select and then use xtransferable - gettransferable/inserttransferable - accessible via the controller
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
wanglong
Posts: 51
Joined: Fri Sep 09, 2022 10:57 am
Location: Beijing,China

Re: Duplicate TextContent to another Doc

Post by wanglong »

Thanks very much,JeJe.

Filnally,I solved this problem with:

Code: Select all

xDispatchHelper.executeDispatch(xDispatchProvider, ".uno:Copy", "", 0, new PropertyValue[]{new PropertyValue()});
xDispatchHelper.executeDispatch(xDispatchProvider, ".uno:Paste", "", 0, new PropertyValue[]{new PropertyValue()});
Libre Office 7.6 on Windows 11.
Post Reply