[Solved] Python-UNO Get chars count from Word's .doc

The Application Programming Interface and the OASIS Open Document Format

[Solved] Python-UNO Get chars count from Word's .doc

Postby fevgeny » Thu Jun 02, 2011 1:44 pm

Hi
I need to get number of the chars from Word 2003 docs. The system is Debian 5.0, OPenOffice 2.4.
I try to do it using python uno.

This code works good:
Code: Select all   Expand viewCollapse view
import uno
local = uno.getComponentContext()
resolver = local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local)
context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
url = "file:////home/asuperevod/asuperevod/lib/python/asulib/primer/001_ru_3338_3893.doc"
document = desktop.loadComponentFromURL(url,"_blank", 0, ())
document.dispose()


But I still can not find out how to get chars count. (Which is /File/Properties/Statistics in GUI)
Using dir() I found document.DocumentInfo.DocumentStatistic, but it is empty.

Could you help me or give me a hint where and how to get information?
Thanks.
Code: Select all   Expand viewCollapse view
print document.DocumentInfo.DocumentStatistic
()
Last edited by fevgeny on Thu Jun 02, 2011 8:27 pm, edited 1 time in total.
OpenOffice 2.4 Debian 5.0
fevgeny
 
Posts: 2
Joined: Thu Jun 02, 2011 1:28 pm

Re: Python-UNO Get chars count from Word's .doc

Postby FJCC » Thu Jun 02, 2011 2:52 pm

The character count is stored in DocumentProperties.DocumentStatistics as a named value. The OOo Basic code would look like:
Code: Select all   Expand viewCollapse view
  oDocumentProperties = oDoc.DocumentProperties
  oDocumentStatistics = oDocumentProperties.DocumentStatistics
  sName = oDocumentStatistics(6).Name
  nValue = oDocumentStatistics(6).Value
  Print sName; nValue

As you can see DocumentStatistics is an array and the 6th element in the character count.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7494
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Python-UNO Get chars count from Word's .doc

Postby B Marcelly » Thu Jun 02, 2011 8:01 pm

Hi,
More direct access :
Code: Select all   Expand viewCollapse view
numberOfChars = document.CharacterCount
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Python-UNO Get chars count from Word's .doc

Postby fevgeny » Thu Jun 02, 2011 8:27 pm

It works! Thank you a lot!
But what is the best way to find properties and methods?
--
I found answer myself, dir(document) does.
OpenOffice 2.4 Debian 5.0
fevgeny
 
Posts: 2
Joined: Thu Jun 02, 2011 1:28 pm


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 1 guest