I need a design macro can anyone help

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
rictec
Posts: 4
Joined: Mon Mar 24, 2008 5:41 pm

I need a design macro can anyone help

Post 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
User avatar
squenson
Volunteer
Posts: 1885
Joined: Wed Jan 30, 2008 9:21 pm
Location: Lausanne, Switzerland

Re: I need a design macro can anyone help

Post 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".
LibreOffice 4.2.3.3. on Ubuntu 14.04
rictec
Posts: 4
Joined: Mon Mar 24, 2008 5:41 pm

Re: I need a design macro can anyone help

Post 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
User avatar
r4zoli
Volunteer
Posts: 2882
Joined: Mon Nov 19, 2007 8:23 pm
Location: Budapest, Hungary

Re: I need a design macro can anyone help

Post by r4zoli »

First read OOo wiki Basic Programming Guide.
Second useful Andrew Pitonyak macro information.
Third Sun documentation.
Usable examples on OOo macros.
AOO 4.0 and LibO 4 on Win 8
Hungarian forum co-admin
rictec
Posts: 4
Joined: Mon Mar 24, 2008 5:41 pm

Re: I need a design macro can anyone help

Post by rictec »

thanks that was helpfull i m reading Andrew docs now
User avatar
Villeroy
Volunteer
Posts: 31344
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: I need a design macro can anyone help

Post 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).
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
rictec
Posts: 4
Joined: Mon Mar 24, 2008 5:41 pm

Re: I need a design macro can anyone help

Post 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
User avatar
Villeroy
Volunteer
Posts: 31344
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: I need a design macro can anyone help

Post 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]
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
Post Reply