[Dropped] Replace text content in Impress

Java, C++, C#, Delphi... - Using the UNO bridges
Locked
Samuel
Posts: 9
Joined: Fri Mar 21, 2025 8:51 am

[Dropped] Replace text content in Impress

Post by Samuel »

Hi all,
I am trying to replace the text content in Impress. I am able to find the text but when i try to replace that specific text, its not changing.I tried using XText.setString but not helpful and also tried to change the shape in which the text is present upon but there also not successful. Please help.
Note: I am doing this in Java.
Last edited by MrProgrammer on Thu Apr 24, 2025 5:02 pm, edited 1 time in total.
Reason: Dropped: No attachment provided
OpenOffice 4.1.15 on Windows11
FJCC
Moderator
Posts: 9549
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: How to replace text content in Impress?

Post by FJCC »

Please provide a specific example of what you want to do by uploading a simple document with an explanation of which text you want to change. To upload a document, click Post Reply and look for the Attachments tab just below the box where you type a response.
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.
JeJe
Volunteer
Posts: 3070
Joined: Wed Mar 09, 2016 2:40 pm

Re: Replace text content in Impress

Post by JeJe »

With MRI:

viewtopic.php?t=49294

Code: Select all

import com.sun.star.container.XIndexAccess;
import com.sun.star.drawing.XDrawPage;
import com.sun.star.drawing.XDrawPages;
import com.sun.star.drawing.XDrawPagesSupplier;
import com.sun.star.drawing.XShape;
import com.sun.star.lang.IndexOutOfBoundsException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.text.XTextRange;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;

public static void snippet(XComponentContext xComponentContext, Object oInitialTarget)
{
	try
	{
		XDrawPagesSupplier xDrawPagesSupplier = UnoRuntime.queryInterface(
			XDrawPagesSupplier.class, oInitialTarget);
		XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
		
		XIndexAccess xIndexAccess = UnoRuntime.queryInterface(
			XIndexAccess.class, xDrawPages);
		XDrawPage xDrawPage = UnoRuntime.queryInterface(
			XDrawPage.class, xIndexAccess.getByIndex(0));
		
		XIndexAccess xIndexAccess2 = UnoRuntime.queryInterface(
			XIndexAccess.class, xDrawPage);
		
		XShape xShape = UnoRuntime.queryInterface(
			XShape.class, xIndexAccess2.getByIndex(0));
		
		XTextRange xTextRange = UnoRuntime.queryInterface(
			XTextRange.class, xShape);
		xTextRange.setString("dfgdfjfg");
		
	}
	catch (WrappedTargetException e1)
	{
		// getByIndex
		e1.printStackTrace();
	}
	catch (IndexOutOfBoundsException e2)
	{
		// getByIndex
		e2.printStackTrace();
	}
}
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Locked