[Solved] Obtain page properties when cursor is on a table

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Kovalevskaya
Posts: 11
Joined: Fri Nov 30, 2018 8:04 pm

[Solved] Obtain page properties when cursor is on a table

Post by Kovalevskaya »

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!
Last edited by Hagar Delest on Sat Oct 19, 2019 1:51 pm, edited 2 times in total.
Reason: tagged solved
OpenOffice 5.1.6.2 Ubuntu 16.04
User avatar
Zizi64
Volunteer
Posts: 11358
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: How obtain the page properties when the cursor is on a t

Post by Zizi64 »

I'm trying to change the page style in a Write document using the Java API.
Is there only one page style applied in the document?

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.
Kovalevskaya
Posts: 11
Joined: Fri Nov 30, 2018 8:04 pm

Re: How obtain the page properties when the cursor is on a t

Post by Kovalevskaya »

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 :D

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");
}
I tried also using the page cursor but the result is the same :( .

Thanks!
Attachments
Example.odt
(8.21 KiB) Downloaded 149 times
OpenOffice 5.1.6.2 Ubuntu 16.04
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: How obtain the page properties when the cursor is on a t

Post by hubert lambert »

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):

Code: Select all

	doc = thiscomponent
	viewcursor = doc.CurrentController.ViewCursor
	table = viewcursor.TextTable
	viewcursor.gotoRange(table.Anchor, False)
To put the view cursor after the table, append these lines to the previous ones (in basic):

Code: Select all

	T = doc.Text
	textcursor = T.createTextCursor()
	textcursor.gotoRange(viewcursor, False)
	textcursor.gotoNextParagraph(False)
	viewcursor.gotoRange(textcursor, False)
Regards.
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: How obtain the page properties when the cursor is on a t

Post by JeJe »

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)
Kovalevskaya
Posts: 11
Joined: Fri Nov 30, 2018 8:04 pm

Re: How obtain the page properties when the cursor is on a t

Post by Kovalevskaya »

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 :super: :super:
OpenOffice 5.1.6.2 Ubuntu 16.04
Post Reply