[Solved] Get TextFrames in Text Document with Java?

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

[Solved] Get TextFrames in Text Document with Java?

Post by wanglong »

How can I get TextFrame Objects already has been added to Text Document with JAVA?
I didn't found a relevant tutorials with this topic.
Please show me with non scripting language!
Thank you very much!
Last edited by wanglong on Fri Sep 09, 2022 4:36 pm, edited 1 time in total.
Libre Office 7.6 on Windows 11.
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: How can I get TextFrames in Text Document with JAVA?

Post by FJCC »

I do not use Java but I recorded the following code with the MRI extension. The oInitialTarget is the text document, the object you would get with ThisComponent in Basic.

Code: Select all

import com.sun.star.container.NoSuchElementException;
import com.sun.star.container.XNameAccess;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.text.XTextFrame;
import com.sun.star.text.XTextFramesSupplier;
import com.sun.star.uno.RuntimeException;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;

public static void snippet(XComponentContext xComponentContext, Object oInitialTarget)
{
	try
	{
		XTextFramesSupplier xTextFramesSupplier = UnoRuntime.queryInterface(
			XTextFramesSupplier.class, oInitialTarget);
		XNameAccess xNameAccess = xTextFramesSupplier.getTextFrames();
		
		XTextFrame xTextFrame = UnoRuntime.queryInterface(
			XTextFrame.class, xNameAccess.getByName("FlowerImage"));
		
	}
	catch (NoSuchElementException e1)
	{
		// getByName
		e1.printStackTrace();
	}
	catch (WrappedTargetException e2)
	{
		// getByName
		e2.printStackTrace();
	}
	catch (RuntimeException e3)
	{
		// getByName
		e3.printStackTrace();
	}
}
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How can I get TextFrames in Text Document with JAVA?

Post by Villeroy »

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
wanglong
Posts: 50
Joined: Fri Sep 09, 2022 10:57 am
Location: Beijing,China

Re: How can I get TextFrames in Text Document with JAVA?

Post by wanglong »

Thanks for your reply so quickly!
Libre Office 7.6 on Windows 11.
Post Reply