Jump to content

Copy Paste Help


Recommended Posts

Im trying to copy text from an historcal encylcopedia application to word document...But it can copy only 20 lines at a time using CTRL+A,CTRL+C,CTRL+V or any other combination like Shift+CTRL+END or using mouse etc etc...Wen i used controlgetext,I got the text but all formatting like font,bold etc is lost coz the class is richtext...Formatting is very imporant to me ....

So how should i approach it now?

a) Copy-Paste 20 lines and Loop to select entire document??Can anyone provide the code or best way to loop it ?

b)Somhow get the formatting by controlgetext ?Is it possible by some rich text plugins or classes??

c)Any other alternate methods?

Link to comment
Share on other sites

Im trying to copy text from an historcal encylcopedia application to word document...But it can copy only 20 lines at a time using CTRL+A,CTRL+C,CTRL+V or any other combination like Shift+CTRL+END or using mouse etc etc...Wen i used controlgetext,I got the text but all formatting like font,bold etc is lost coz the class is richtext...Formatting is very imporant to me ....

So how should i approach it now?

a) Copy-Paste 20 lines and Loop to select entire document??Can anyone provide the code or best way to loop it ?

b)Somhow get the formatting by controlgetext ?Is it possible by some rich text plugins or classes??

c)Any other alternate methods?

Without your code it would be something akin to trying to diagnose a squeak in a vehicle over a long distance telephone line.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Without your code it would be something akin to trying to diagnose a squeak in a vehicle over a long distance telephone line.

Oops...Sorry...I will give both my working codes...Looping Shift+Ctrl+END(Tooo Slow....) and ControlGetText(formating lost)..Ima newbie and this is my first AutoIt code,so plz forgive if its clumsy

1)Using ContrlGetText

ClipPut("")
$var1=""
$Title=""
$xpos=82
$ypos=140

Run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE")
;'Document' window is the MS word window
WinWaitActive("Document")

;My History encylopedia Application
Run("D:\CD\VerDIS.exe")

WinWaitActive("HISTORY ENCYCLO - [Home]")
ControlClick ( "HISTORY ENCYCLO  - [Home]", "",16 )
WinActivate("HISTORY ENCYCLO  - [Home]")
WinWaitActive("HISTORY ENCYCLO  - [Home]")
Opt("MouseCoordMode", 2)
;The application has a left tree and document will open in a new window
MouseClick("left",$xpos,$ypos)
MouseClick("left",$xpos,$ypos,2)
WinWaitActive("HISTORY ENCYCLO ")

sleep(4000)
$i=1
Do
$Titleold=""
$Titlenew=WinGetTitle ("HISTORY ENCYCLO ")
While $Titlenew <> $Titleold

;Here i get the document text from controlclass RichTextWndClass2

$var1=StringReplace(ControlGetText("HISTORY ENCYCLO ","","RichTextWndClass2"), @LF, @CRLF)
;Title is trimmed and used for file name for  word files
$Title=WinGetTitle ("HISTORY ENCYCLO ")
$Title= StringReplace($Title, "HISTORY ENCYCLO  - [", " ")
$Title= StringReplace($Title, "]", " ")
$Title= StringReplace($Title, ":", " ")
$Title= StringReplace($Title, ".", " ")



If $var1 <> "" Then

ClipPut($var1)

;Document window is the MS word window

WinActivate("Document")
WinWaitActive("Document")
Send('^{v}')
Sleep(4000)
Send("!{f}")
Send("{c}")
WinWaitActive("Microsoft Office")
Send("!{y}")
WinWaitActive("Save As")
ClipPut("")
ClipPut($Title)
Sleep(1000)
Send('^{v}')
Send("{ENTER}")
Send("^{n}")
WinWaitActive("Document")
WinActivate("HISTORY ENCYCLO")
WinWaitActive("HISTORY ENCYCLO")
    
Else
    
    $file1 = FileOpen("error.txt",1)
    FileWrite($file1,$Title & @CRLF)
    FileClose($file1)

EndIf
$Titleold=$Titlenew
$i=$i+1
ClipPut("")
MouseClick("left",330,56)
sleep(2000)

$Titlenew=WinGetTitle ("HISTORY ENCYCLO ")
if $Titleold=$Titlenew Then
    If $i>=17 Then
        Send("^{TAB}")
        sleep(1000)
        $ypos=$ypos+25
        MouseClick("left",$xpos,$ypos)
        $ypos=$ypos-25
        MouseClick("left",$xpos,$ypos,2)
        WinWaitActive("HISTORY ENCYCLO")
        sleep(2000)
        $Titleold=""
        $Titlenew=WinGetTitle ("HISTORY ENCYCLO")
    Else
        Send("^{TAB}")
        sleep(1000)
        $ypos=$ypos+25
        MouseClick("left",$xpos,$ypos)
        MouseClick("left",$xpos,$ypos,2)
        WinWaitActive("HISTORY ENCYCLO")
        sleep(2000)
        $Titleold=""
        $Titlenew=WinGetTitle ("HISTORY ENCYCLO")
    EndIf
EndIf
WEnd
Until $i=84
Link to comment
Share on other sites

2) Copying 20 lines and saving to word and looping it...Formatting is OK,but its too slow and clumsy

ClipPut("")
Run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE")
WinWaitActive("Document")
Run("D:\CD\VerDIS.exe")
WinWaitActive("HISTORY ENCYCLO- [Home]")
ControlClick ( "HISTORY ENCYCLO - [Home]", "",16 )
WinActivate("HISTORY ENCYCLO - [Home]")
WinWaitActive("HISTORY ENCYCLO - [Home]")
MouseClick("left",82,144)
MouseClick("left",82,144,2)
WinWaitActive("HISTORY ENCYCLO")
sleep(2000)
$i=1
While $i <= 283

$Title=""
    
MouseClick("left",26,107)
$j=1
Do

;This is used for selecting about 20 lines possible
Send("{SHIFTDOWN}")
Send("^{END}")
Send("{SHIFTUP}")
Send("^{c}")
sleep(1000)
$var2=ClipGet()

if($var2="") Then
    
    $j=0
    Send("{RIGHT}")
    Send("^{HOME}")
Else
    Send("{RIGHT}")
    WinActivate("Document")
    WinWaitActive("Document")
    Send("^{v}")
    WinActivate("HISTORY ENCYCLO")
    WinWaitActive("HISTORY ENCYCLO")
EndIf

Until $j=0

$Title=WinGetTitle ("HISTORY ENCYCLO")
$Title= StringReplace($Title, "HISTORY ENCYCLO - [", " ")
$Title= StringReplace($Title, "]", " ")
$Title= StringReplace($Title, ":", " ")
$Title= StringReplace($Title, ".", " ")



WinActivate("Document")
WinWaitActive("Document")
Send("!{f}")
Send("{c}")
WinWaitActive("Microsoft Office")
Send("!{y}")
WinWaitActive("Save As")
ClipPut("")
ClipPut($Title)
Sleep(1000)
Send('^{v}')
Send("{ENTER}")
Send("^{n}")
WinWaitActive("Document")
WinActivate("HISTORY ENCYCLO")
WinWaitActive("HISTORY ENCYCLO")
    

$i=$i+1
ClipPut("")

Send("^{HOME}")
sleep(1000)
MouseClick("left",330,56)
sleep(2000)

WEnd
Edited by maxilla
Link to comment
Share on other sites

Still waiting :-)

I tried to sens a long reply yesterday but my ISP was having a problem. So I'll try to remember it now.

Clumsy is not a major problem as long as the code is readable and yours isn't too bad.

As it happens I'm working on a UDF for MS Word right now. I've been working on creating Word tables but I'll try to jump ahead to formatted text. Give me a few hours with that since I also have other projects on the go.

It would be handy if you can post a link to a download of VerDIS so that I can take a peek at any particular file structure they are using (there may be an easier method).

Assuming that the button you are clicking on is a Copy button, what happens when you copy the code manually and then paste it into a Word doc? Do you still lose the formatting?

Here are a couple of things that you can do in the meantime to clean up the code.

Add Opt("WinTitleMatchMode", 2) near the top of the script.

Add $Ettl = "HISTORY ENCYCLO - [Home]"

Add $dTtl = "Document"

Change all of the Win Functions from "HISTORY ENCYCLO - [Home]" to $Ettl

Do the same for the Win functions that refer to "document. Of course those wil be $dTtl

You do not need

Send("{SHIFTDOWN}")

Send("^{END}")

Send("{SHIFTUP}")

Just use Send("+^{END}")

Try to post that link ASAP so I can take a look at the files.

I hope this gets through this time.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

THANK YOU FOR YOUR REPLY...

SORRY TO SAY I DONT HAVE THE VERDIS APPLICATION CD WITH ME...IT WAS INSTALLED FROM MY FRIENDS CD AND I CANT FIND HIM NOW...

Assuming that the button you are clicking on is a Copy button, what happens when you copy the code manually and then paste it into a Word doc? Do you still lose the formatting?

As i said earlier,i can copy 20 lines only at a time manually...When i loop this 20 lines until document is over(see my 2nd script) using autoitscript,im not losing format but its very very slow as i have to switch between application and word window and copy paste each time i copy 20 lines...

im losing format when i use controlgettext function(see my first script )...formatting is very important to me...

Also one more thing...in my 2nd program u can see me switching between word and application and saving clipboard contents after every 20 lines i copy...can i avoid it???

i tried the store the cibboard values in a varible until document is fully copied and using clipput($var) to save in word after the copy is over..but that again loses formatting :whistle:

Edited by maxilla
Link to comment
Share on other sites

THANK YOU FOR YOUR REPLY...

SORRY TO SAY I DONT HAVE THE VERDIS APPLICATION CD WITH ME...IT WAS INSTALLED FROM MY FRIENDS CD AND I CANT FIND HIM NOW...

As i said earlier,i can copy 20 lines only at a time manually...When i loop this 20 lines until document is over(see my 2nd script) using autoitscript,im not losing format but its very very slow as i have to switch between application and word window and copy paste each time i copy 20 lines...

im losing format when i use controlgettext function(see my first script )...formatting is very important to me...

Also one more thing...in my 2nd program u can see me switching between word and application and saving clipboard contents after every 20 lines i copy...can i avoid it???

i tried the store the cibboard values in a varible until document is fully copied and using clipput($var) to save in word after the copy is over..but that again loses formatting :whistle:

You might be better off to add each to the clipboard as you go

ClipPut($Var)

Run Your Code

ClipPut(ClipGet() & $Var)

How about posting a screen shot of the page so we can see what you are attempting to do

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...