Add text to empty lines in Word

Asked by Glenna

I have a word doc that looks like this:

Click this button.

Click this menu.

Click the search
for box.

Type 1234 then press
TAB.

Click A.

I want Sikuli to type "Slide" on each of the empty lines, but because some of the text are broken into two lines, it creates a headache for me. Any ideas?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

not really a typical job for Sikuli.

How do you do that, if the text would only contain one-liners? (your current approach as snippet?)

Revision history for this message
Jonas Maurer (jonas-maurer) said :
#2

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.

Can you help with this problem?

Provide an answer of your own, or ask Glenna for more information if necessary.

To post a message you must log in.