← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #252716]: Add text to empty lines in Word

 

Question #252716 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/252716

    Status: Needs information => Answered

Jonas Maurer proposed the following answer:
I think I have a few ideas.

first one is being the following: mark the entire area with either mouse selection or select everyting using
type("a",Keymodifier.CTRL)

and then cut it using

type("x",Keymodifier.CTRL)

now, create a object and store the clipboard content:

string = Env.getClipboard()

and here comes the tricky part: use regular expressions in order to match each occurence of "\r\n\r\n" in the string and replace it with "\r\nSlide\r\n". store the resulting modified string in a different object (like result)
(If there may be whitespace characters in your word document on the empty lines then search for \r\n[\t ]*\r\n instead)

note that windows uses a carriage return character (\r) and a newline
character (\n) in sequence to mark a line break, (linux only uses the
newline character)

now, paste the modified string back to the word document:

paste(result)

and then when you are done, every empty line will now contain "Slide"

You have to read up on regular expressions in order to use my solution,
but the solution would work safely.

I had a second solution in mind that would do the same on a image level,
but that solution would be way more complicated to pull off and far less
robust (It involves generating a long 1 pixel wide region to match with
a 7-10 pixel high x 1 pixel wide blank image and then type "slide" at
every occurence)

There are also more solutions that are probably simpler than any
solutions who make use of sikulix: Learn about the macro tools that
microsoft word has (they are pretty useful). The other option is visual
basic for applications.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.