Hi everyone, I have a small question. I'm trying to change the page style in a Write document using the Java API.
I can change the page style setting the PageDescName property obtained from a XTextViewCursor but
I can't change the page style, in that way , when the cursor is on a table
¿How can I obtain the page properties when the cursor is placed on a table?
Thanks!
[Solved] Obtain page properties when cursor is on a table
-
- Posts: 11
- Joined: Fri Nov 30, 2018 8:04 pm
[Solved] Obtain page properties when cursor is on a table
Last edited by Hagar Delest on Sat Oct 19, 2019 1:51 pm, edited 2 times in total.
Reason: tagged solved
Reason: tagged solved
OpenOffice 5.1.6.2 Ubuntu 16.04
Re: How obtain the page properties when the cursor is on a t
Is there only one page style applied in the document?I'm trying to change the page style in a Write document using the Java API.
Can you upload a sample document with the macro code here?
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
-
- Posts: 11
- Joined: Fri Nov 30, 2018 8:04 pm
Re: How obtain the page properties when the cursor is on a t
Hi Zizi 64! Thank you for your answer. The document could have more than one page.
And yes I can attach some of the code that I'm writing
I tried also using the page cursor but the result is the same .
Thanks!
And yes I can attach some of the code that I'm writing
Code: Select all
public void changeStyle(short page,OfficeDocument document)
{
XPageCursor pc;
XViewCursor cursor;
pc.jumpToPage(page);
pc.jumpToStartOfPage();
//getViewCursor is a method that obtains the View Cursor
cursor = getViewCursor(document);
XPropertySet propsc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,cursor);
//NewStyle is an existing style
propsc.setPropertyValue("PageDescName", "NewStyle");
}
Thanks!
- Attachments
-
- Example.odt
- (8.21 KiB) Downloaded 151 times
OpenOffice 5.1.6.2 Ubuntu 16.04
-
- Posts: 145
- Joined: Mon Jun 13, 2016 10:50 am
Re: How obtain the page properties when the cursor is on a t
Hi,
The PageDescName property "creates a page break before the paragraph it belongs to and assigns the value as the name of the new page style sheet to use" (from the api documentation).
Yet you can't insert a page break to a paragraph inside a text table. In other words, you can't have a text table spanning over two pages that have different styles.
You can test if your cursor is inside a table by checking its "TextTable" property.
To put the view cursor before the table (in basic):
To put the view cursor after the table, append these lines to the previous ones (in basic):
Regards.
The PageDescName property "creates a page break before the paragraph it belongs to and assigns the value as the name of the new page style sheet to use" (from the api documentation).
Yet you can't insert a page break to a paragraph inside a text table. In other words, you can't have a text table spanning over two pages that have different styles.
You can test if your cursor is inside a table by checking its "TextTable" property.
To put the view cursor before the table (in basic):
Code: Select all
doc = thiscomponent
viewcursor = doc.CurrentController.ViewCursor
table = viewcursor.TextTable
viewcursor.gotoRange(table.Anchor, False)
Code: Select all
T = doc.Text
textcursor = T.createTextCursor()
textcursor.gotoRange(viewcursor, False)
textcursor.gotoNextParagraph(False)
viewcursor.gotoRange(textcursor, False)
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
Re: How obtain the page properties when the cursor is on a t
The macro recorder produces this for the dispatch helper (in Basic)... so if it can be translated to Java...
Code: Select all
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Template"
args1(0).Value = "Right Page"
args1(1).Name = "Family"
args1(1).Value = 8
dispatcher.executeDispatch(document, ".uno:StyleApply", "", 0, args1())
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
-
- Posts: 11
- Joined: Fri Nov 30, 2018 8:04 pm
Re: How obtain the page properties when the cursor is on a t
Thank you guys! I'm going to apply some of that methods to change the style , but I understand that there is no a simple way to obtain the XTextViewCursor of the page when the cursor is placed inside the table. However there is another ways to change the page style.
Thank you
Thank you
OpenOffice 5.1.6.2 Ubuntu 16.04