[Solved] Properties - average number of words per page

Discuss the word processor
Post Reply
tony_photoplus
Posts: 12
Joined: Thu Dec 27, 2007 6:17 pm

[Solved] Properties - average number of words per page

Post by tony_photoplus »

Hi, wondering if someone has an easy answer for my problem. I need to know the average number of words per page. How do I set it up and how do I get it to show in the properties? I need to know this for the novel I am writing.
Last edited by Villeroy on Fri Aug 06, 2010 8:59 pm, edited 1 time in total.
User avatar
Hagar Delest
Moderator
Posts: 32628
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Properties - average number of words per page

Post by Hagar Delest »

The first idea I can think of is to use a table with 3 cells: put fields inside (Insert>Fields>Other>Document tab) the first 2 cells for the number of words and the number of page. In the 3rd cell, hit F2 to display the formula toolbar and then click the cell with the number of words, then then "/" operator and then the second cell with the number of pages. Hit return and there it is.

Please add '[Solved]' at beginning of your first post title (edit button) if your issue has been fixed.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Properties - average number of words per page

Post by RoryOF »

Your number of words is shown in Properties (Caveat: OOo miscounts because of quotes and apostrophes, so shows more words than a hand-count - at least, it used to do so). Your number of pages is shown on the left of the status bar. Divide one by the other and you will get a ballpark figure. This depends on OOo's word count, and page size (smaller pages = fewer words). Normally a publisher cares only about total word-count. Typically in non-technical English text divide number of characters in a file by 5.5 and you have a word-count (just verified it on War and Peace).
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Properties - average number of words per page

Post by Zizi64 »

Here is a solution with macro.
The code is based on example code of:
http://user.services.openoffice.org/en/ ... 20&t=17358
You can copy the code into OOo Standard library, and you can associate the sub "PrintWordAverage" to a new Menu item (customize Toolbar).
The code works exactly after Save of document.

Code: Select all

REM  *****  BASIC  *****
Option Explicit

sub PrintWordAverage
dim WordAverage as double
WordAverage = GetWordCount()/GetPageCount()
MsgBox(WordAverage, 64, "The average number of words per page:")
end sub



Function getPageCount as integer
	getPageCount = ThisComponent.CurrentController.PageCount
End Function


Function getWordCount as integer
dim oDoc as object
dim oProps as object
dim aStats as object
dim i as integer
dim x as object

oDoc = ThisComponent
oProps = oDoc.getDocumentProperties()

REM or pseudo-property: oProps = oDoc.DocumentProperties
aStats = oProps.DocumentStatistics ' true property
REM oDoc.getDocumentStatistics() is not a valid method call
REM Loop through the array of c.s.s.beans.NamedValue
for i = uBound(aStats) to 0 step -1
 x = aStats(i)
 if x.Name = "WordCount" then exit for
next
getPageCount = 0
if i > -1 then getWordCount = x.Value
'getWordCount = ThisComponent.CurrentController.WordCount
End Function
Last edited by Zizi64 on Fri Aug 06, 2010 6:46 pm, edited 1 time in total.
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.
User avatar
Hagar Delest
Moderator
Posts: 32628
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Properties - average number of words per page

Post by Hagar Delest »

You just have now to find a snippet about creating the custom information for the properties field.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Properties - average number of words per page

Post by Villeroy »

Hagar de l'Est wrote:You just have now to find a snippet about creating the custom information for the properties field.
Here you are. The code to add user defined property "Words per Page" does not work. The code requires that you have that custom property already set in your template.
Attachments
wpp.odt
Simple custom field with update by button
(10.28 KiB) Downloaded 165 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Properties - average number of words per page

Post by Zizi64 »

Hagar de l'Est wrote:You just have now to find a snippet about creating the custom information for the properties field.
Here you are. The code to add user defined property "Words per Page" does not work. The code requires that you have that custom property already set in your template.
It is for me?

Villeroy, your code:
The code is based on example code of:
viewtopic.php?f=20&t=17358
works for me fine. I have completed it a few lines...
Average.odt
(10.37 KiB) Downloaded 159 times
Average.png
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.
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Properties - average number of words per page

Post by Villeroy »

I added the information about words per page to the custom properties (menu:File>Properties...), so the figure can be displayed anywhere in the document like a page count field or time stamp (menu:Insert>Fields>Other... tab:DocInfo,type:Custom]. WHat I did not get right, is how to add such a custom property to the ducument. I had to comment out this line:

Code: Select all

if not psi.hasPropertyByName(cUDP) then udp.addProperty(cUDP,0,WordAverage)
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
tony_photoplus
Posts: 12
Joined: Thu Dec 27, 2007 6:17 pm

Re: Properties - average number of words per page

Post by tony_photoplus »

Wow what a response thanks all. I am very grateful, thank you
User avatar
Hagar Delest
Moderator
Posts: 32628
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Properties - average number of words per page

Post by Hagar Delest »

Zizi64 wrote:It is for me?
:oops:
No, sorry, I should have made it clearer, it was for the OP!
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Post Reply