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

Creating a macro - Writing a Script - Using the API

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

Postby Kovalevskaya » Thu Oct 10, 2019 11:44 pm

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

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

Postby Zizi64 » Fri Oct 11, 2019 6:45 am

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; LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.3.2; AOO4.1.6
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.
User avatar
Zizi64
Volunteer
 
Posts: 8474
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Postby Kovalevskaya » Tue Oct 15, 2019 8:27 pm

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   Expand viewCollapse view
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 6 times
OpenOffice 5.1.6.2 Ubuntu 16.04
Kovalevskaya
 
Posts: 10
Joined: Fri Nov 30, 2018 8:04 pm

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

Postby hubert lambert » Wed Oct 16, 2019 9:26 pm

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   Expand viewCollapse view
   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   Expand viewCollapse view
   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
hubert lambert
 
Posts: 132
Joined: Mon Jun 13, 2016 10:50 am

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

Postby JeJe » Thu Oct 17, 2019 11:56 am

The macro recorder produces this for the dispatch helper (in Basic)... so if it can be translated to Java...

Code: Select all   Expand viewCollapse view

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

Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 610
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby Kovalevskaya » Thu Oct 17, 2019 5:38 pm

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


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests