[Solved Elsewhere] A Specific Macro with Find-Replace?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
User avatar
robleyd
Moderator
Posts: 5055
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: A Specific Macro with Find-Replace?

Post by robleyd »

So there is no duplication of effort, this same question is asked on the Ask LibO site under a different username.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.1.2; SlackBuild for 24.2.1 by Eric Hameleers
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

Re: A Specific Macro with Find-Replace?

Post by rajibando »

Roblyed took all the troubles to post the above info post to ask.libreoffice also.
As an aside, the contribution of Librebel was acknowledged in the very first post here: A Specific Macro with Find-Replace? None has yet solved the case. So duplication doesn't yet occur. Everyone has been duly informed, as far as possible, that Zizi was also working on it.
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

Re: A Specific Macro with Find-Replace?

Post by rajibando »

I found that I can catch the "↲¶" combination with the normal Find-Replace (Ctrl+H) using the string "\n$". But when I use the same string in the macro, like "\n" + "$", or "\n$" and try to replace it with `ch(10)` I can't.
Why?
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: A Specific Macro with Find-Replace?

Post by hubert lambert »

Hello,

Perhaps something like this would do the trick:

Code: Select all

sub main
    doc = thiscomponent
    rajibando_find_and_remplace(doc.Text)
end sub

sub rajibando_find_and_remplace(T)
    do
        for each para in T
            if T.compareRegionEnds(T, para) = 0 then
                exit sub
            end if
            c = T.createTextCursorByRange(para.End)
            c.goRight(2, True)
            firstchar = mid(c.String, 3, 1)
            if not isnumeric(firstchar) then
                c.String = chr(10) & firstchar
                exit for
            end if
        next para
    loop
end sub
On linux amend this way:

Code: Select all

            firstchar = mid(c.String, 2, 1)
 Edit: More simple, to stay plateform independant:

Code: Select all

            firstchar = mid(c.String, len(c.String), 1)
 
Attachments
rajibando (linux).odt
(16.26 KiB) Downloaded 177 times
rajibando.odt
(16.28 KiB) Downloaded 182 times
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

[Solved]Re: A Specific Macro with Find-Replace?

Post by rajibando »

This problem was totally solved here: A Specific Macro with Find-Replace? by Hubert Lambert.
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
Post Reply