In the documentation I found:
But the next code doesn't work:The PageStyle is set at the current text cursor position by setting the property PageDescName to an existing page style name.This will insert a new page that uses the new page style. If no new page should be inserted, the cursor has to be at the beginning of the first paragraph.
Code: Select all
XTextDocument xTextDocument = (com.sun.star.text.XTextDocument)
UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class, xComponent);
XController xController = xTextDocument.getCurrentController();
XTextViewCursorSupplier xViewCursorSupplier = UnoRuntime.queryInterface(
XTextViewCursorSupplier.class, xController);
XTextViewCursor xViewCursor = xViewCursorSupplier.getViewCursor();
XPageCursor xPageCursor = UnoRuntime.queryInterface(XPageCursor.class, xViewCursor);
xPageCursor.jumpToFirstPage();
xPageCursor.jumpToNextPage();
xPageCursor.jumpToStartOfPage();
xPageCursorProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xPageCursor);
xPageCursorProps.setPropertyValue("PageDescName", "Style2");
I
Also I found example on Basic, but I don't know how to translate it to Java:
Code: Select all
sub Page_styles_convert1
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Template"
args1(0).Value = "Beige_Default"
args1(1).Name = "Family"
args1(1).Value = 8
For i = 0 To 276
dispatcher.executeDispatch(document, ".uno:StyleApply", "", 0, args1())
dispatcher.executeDispatch(document, ".uno:GoToNextPage", "", 0, Array())
Next
end sub