Page 1 of 1

I need a design macro can anyone help

Posted: Mon Mar 24, 2008 5:57 pm
by rictec
I need a macro that
count the how many times a text sequence like "[number]" apears inside on a doc
sum all the numbers inside the brackets
generate a doc with proprieties of the file like date, filename, how many ocurrences and the sum of the numbers..

can anyone help me on this?

Rictec

Re: I need a design macro can anyone help

Posted: Tue Mar 25, 2008 7:45 am
by squenson
The purpose of this forum is not to write complete macros for people, but to help with issues or "how-to". For the help you require, I would suggest that either you try by yourself and ask questions when you are blocked, or you ask a forum administrator to move your thread to the section "Paid support".

Re: I need a design macro can anyone help

Posted: Tue Mar 25, 2008 11:19 am
by rictec
thank you for your input...as you saying unless i paid no one is going to help me on this?
i don t think that paying someone to do it helps, cos i was after learning how to do it on write basic or even if something like this is possible on write.
Maybe someone else helps me untill then i have some reading to do ;)

Rictec

Re: I need a design macro can anyone help

Posted: Tue Mar 25, 2008 11:41 am
by r4zoli
First read OOo wiki Basic Programming Guide.
Second useful Andrew Pitonyak macro information.
Third Sun documentation.
Usable examples on OOo macros.

Re: I need a design macro can anyone help

Posted: Tue Mar 25, 2008 12:10 pm
by rictec
thanks that was helpfull i m reading Andrew docs now

Re: I need a design macro can anyone help

Posted: Tue Mar 25, 2008 3:30 pm
by Villeroy
From your description I would estimate that "the real one and only IT professional" would never waste hours of time to write an office macro for this trivial task. You could save the document as plain text and let a tiny script do the job (should be doable with a single command in the Perl programming language).

Re: I need a design macro can anyone help

Posted: Wed Mar 26, 2008 2:34 pm
by rictec
Thats an ideia and a very good one i will check that possibility still i need to learn how that can be done with a macro

Thank you

Re: I need a design macro can anyone help

Posted: Wed Mar 26, 2008 3:32 pm
by Villeroy
Sigh, I did it again!

Code: Select all

import uno, sre
from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
   
def sum_num():
    thisComponent = XSCRIPTCONTEXT.getDocument()
    oText = thisComponent.getText()
    oCursor = oText.createTextCursor()
    txt = oText.getString()
    regex = '\[([0-9]+)\]'
    oPattern = sre.compile(regex)
    aMatches = sre.findall(oPattern, txt)
    result = 0
    for m in aMatches:
        result += int(m)
    oCursor.gotoEnd( False )
    oText.insertControlCharacter( oCursor, PARAGRAPH_BREAK, False )
    oText.insertString( oCursor, 'SUM: '+ unicode(result), False )

g_exportedScripts = sum_num,
Save with UNIX line feeds as <ooo_profile>/user/Scripts/python/sum_num.py
Activate your text document and call
Menu:Tools>Macros>Organize>Python... sum_num > sum_num [Run]