Good Day,
I'm working on a simple test Program to learn UNO.
It's written in Java and I know want the Program to:
[SOLVED]Open a .odt
[SOLVED]Look for Pictures
[SOLVED]Read out the names of them
Replace the names.
Does anyone know how I can replace the Pictures Name?
Thank's for your help.
Best Regards,
pr0t0n3
Sorry for my bad english I come from Austria.
[Solved] Replace Pictures Name with UNO
[Solved] Replace Pictures Name with UNO
Last edited by protone on Wed Jun 30, 2010 1:47 pm, edited 1 time in total.
OpenOffice 3.2 on Windows 7 / OOPortable on Stick
Re: Replace Pictures Name with UNO
Using MRI i recorded this bit of Basic code to change the name of a picture.
The oInitialTarget is the odt document. The Java version produced by MRI is
Does that help?
Code: Select all
Sub Snippet(Optional oInitialTarget As Object)
Dim oDrawPage As Object
Dim oObj_1 As Object
oDrawPage = oInitialTarget.DrawPage
oObj_1 = oDrawPage.getByIndex(0)
oObj_1.setName("MyNewName")
End Sub
Code: Select all
import com.sun.star.container.XIndexAccess;
import com.sun.star.container.XNamed;
import com.sun.star.drawing.XDrawPage;
import com.sun.star.drawing.XDrawPageSupplier;
import com.sun.star.drawing.XShape;
import com.sun.star.lang.IndexOutOfBoundsException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.uno.UnoRuntime;
static public void snippet(Object oInitialTarget)
{
try
{
XDrawPageSupplier xDrawPageSupplier = UnoRuntime.queryInterface(
XDrawPageSupplier.class, oInitialTarget);
XDrawPage xDrawPage = xDrawPageSupplier.getDrawPage();
XIndexAccess xIndexAccess = UnoRuntime.queryInterface(
XIndexAccess.class, xDrawPage);
XShape xShape = UnoRuntime.queryInterface(
XShape.class, xIndexAccess.getByIndex(0));
XNamed xNamed = UnoRuntime.queryInterface(
XNamed.class, xShape);
xNamed.setName("MyNewName");
}
catch (WrappedTargetException e1)
{
// getByIndex
e1.printStackTrace();
}
catch (IndexOutOfBoundsException e2)
{
// getByIndex
e2.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.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Replace Pictures Name with UNO
Yes, great thank you. I will try it later on, but this looks very good.
Regards,
pr0t0ne
Regards,
pr0t0ne
OpenOffice 3.2 on Windows 7 / OOPortable on Stick