Ask Your Question
0

Is a page-scope counter possible?

asked 2018-02-27 18:55:34 +0200

severoraz gravatar image

I am trying to implement a page-scope counter (that is, a counter with the scope of one page) to count a number of elements in each page, dynamically. Is this possible in LO?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2018-02-27 20:20:54 +0200

Lupp gravatar image

You will surely know that pages (like lines) aren't fixed objects in a Writer document. They are generated on the fly to present the layout. In addition not every "element" created for a document is contained in "the text". Frames and also shapes are child objects of ThisComponent.DrawPage and have their own text object properties. Frames and shapes have an anchor of one or another type defining their relation to the text flow...

If you exclusively want to count characters of the general text belonging to a specific page under the current layout, you may use the .String property of the TextCursor returned by the following user function (BASIC):

Function getPageAsTextCursor() As Object
doc0   = ThisComponent
text0  = doc0.Text
tVC    = doc0.CurrentController.GetViewCursor
tVCold = text0.createTextCursorByRange(tVC)
tVCold.GotoRange(tVC, False)
pgTC   = text0.createTextCursorByRange(tVC)
tVC.JumpToStartOfPage()
pgTC.GotoRange(tVC.Start, False)
tVC.JumpToEndOfPage()
pgTC.GotoRange(tVC.End, True)
tVC.GotoRange(tVCold, False)
getPageAsTextCursor _
       = pgTC
End Function

"The page" will be the one containing the logical .End of the current ViewCursor.
Frames and shapes will not be regarded. I did not thoroughly research many details.
You may have to study programming for LibreOffice to more depth. Did you already find the famous texts by Andrew Pitonyak?

edit flag offensive delete link more

Comments

Thanks for the answer, and for the code! I really appreciate it. I haven't looked very deeply into LO macro programming, but it seems I may have to.

severoraz gravatar imageseveroraz ( 2018-02-28 13:09:34 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-02-27 18:55:34 +0200

Seen: 27 times

Last updated: Feb 27 '18