 | OO-Snippets: Count words of the selected text with ooRexxCommons| Keywords | count, words, ooRexx |
|---|
| Language | ooRexx |
|---|
| Application | Writer |
|---|
| Authors | Josef Frysak (initial)
|
|---|
| Supported Versions | 2.4.1 |
|---|
| Supported OS | All |
|---|
| Question | How to count the words of selected text?
|
|---|
| Answer | First get the selected text. Now iterate trough the selection parts and get each of them as a string. Use this string with the "WORDS()" function of ooRexx to count its words. Finally sum up all counts. For further details see http://wi.wu-wien.ac.at/rgf/diplomarbeiten/BakkStuff/2008/200809_Frysak/200809_Frysak_Automating_OOo_ooRexx_Nutshells.pdf. |
|---|
x_ScriptContext = uno.getScriptContext()
if (x_ScriptContext <> .nil) then
do
x_ComponentContext = x_ScriptContext~getComponentContext
x_Desktop = x_ScriptContext~getDesktop
x_Document = x_ScriptContext~getDocument
end
else
do
x_ComponentContext = UNO.connect()
service = "com.sun.star.frame.Desktop"
s_Desktop = x_ComponentContext~getServiceManager~XMultiServiceFactory~createInstance(service)
x_Desktop = s_Desktop~XDesktop
x_Document = x_Desktop~getCurrentComponent()
end
wordcount = 0
x_Model = x_Document~XModel
s_Container = x_Model~getCurrentSelection()
if s_Container <> .nil then
do
x_IndexAccess = s_Container~XIndexAccess
size = x_IndexAccess~getCount()
do counter = 1 to size
s_text = x_IndexAccess~getByIndex(counter - 1)
x_TextRange = s_text~XTextRange
wordstring = x_TextRange~getString()
wordcount = wordcount + WORDS(wordstring)
end
end
.bsf.dialog~messageBox("Counted Words: " || wordcount, "WordCount", "information")
::requires UNO.CLS
|
Changelog| Date | User | Modification |
|---|
| 2008-10-14 | 1 | Initial version |
|