Page 1 of 1
[Dropped] Replace text content in Impress
Posted: Thu Apr 17, 2025 11:28 am
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.
Re: How to replace text content in Impress?
Posted: Thu Apr 17, 2025 1:54 pm
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.
Re: Replace text content in Impress
Posted: Thu Apr 17, 2025 9:19 pm
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();
}
}