Page 1 of 2
Copy cells from CSV and Pasting into chrome
Posted: 20 Jun 2021, 18:08
by rolo6464
Hi guys,
I'm stuck on this problem, would appreciate any help.
I have a CSV that has 2 columns, A and B. And many rows in each column. They are simply dates
I am trying to write a program that copies from column A1 and pastes it into a form in chrome. Then copies Column B1 and pastes it into another form in Chrome. It repeats this process until all the rows are completed, meaning after doing cells A1 and B1, it goes to cells A2 and B2, then A3 and B3, and so on repeating the loop.
Basically like this:
Code: Select all
Fileread: C:\dates.csv
start loop{
copy column A1
mouseclick, left, 384, 254
sendraw, %clipboard%
copy column B1
mouseclick, left, 145, 254
sendraw, %clipboard%
REPEAT LOOP AS MANY TIMES AS NECESSARY UNTIL BLANK
END LOOP}
[Mod edit: [code][/code] tags added.]
something like that, thanks!
Re: Copy cells from CSV and Pasting into chrome
Posted: 22 Jun 2021, 18:56
by rolo6464
@mikeyww
Do you know the solution to this, as you solved a similar problem of mine last time, i'd be happy to pay you via paypal for this. Thanks
Re: Copy cells from CSV and Pasting into chrome
Posted: 22 Jun 2021, 21:12
by mikeyww
There may be more reliable ways with JavaScript or Chrome.ahk, but here is a basic kind of demo with the coordinates that you provided. I imagine that it would need adjustment.
Code: Select all
coord := [[384, 254], [145, 254]]
Loop, Read, %A_ScriptDir%\test.csv
Loop, Parse, A_LoopReadLine, CSV
{ MouseClick,, coord[A_Index].1, coord[A_Index].2
Send %A_LoopField%
}
Re: Copy cells from CSV and Pasting into chrome
Posted: 22 Jun 2021, 22:10
by rolo6464
mikeyww wrote: ↑22 Jun 2021, 21:12
There may be more reliable ways with JavaScript or Chrome.ahk, but here is a basic kind of demo with the coordinates that you provided. I imagine that it would need adjustment.
I really appreciate your reply. Unfortunately I wasn't able to make that work, my skills levels in programming just isn't very advanced so wasn't able to fill in the blanks to make it work. I did have an idea, I could take the code you gave me last time and tweak it a bit. I was thinking instead of having 2 columns I can easily modify the data to fit into 1 column, but the tricky part now is alternating coordinates for each one, So cell A1 is coordinate 1 and cell A2 is coordinate 2, cell A3 is coordinate 1 and A4 is coordinate 2.
This is what I have so far, its almost there just need to figure out either to use column B values or simply paste the next cell value before restarting the loop
Code: Select all
file = C:\1.HardDrive\test.csv
started := False
Loop, Read, %file%
{ Loop, Parse, A_LoopReadLine, CSV
{ If (A_Index != 1)
Continue
If A_LoopField {
MouseClick, left, 237, 684 ;<-- coordinate 1
Send %A_LoopField%
sleep, 2000
MouseClick, left, 408, 684 ;<--- coordinate 2
Send %A_LoopField% ;<--- should be either column B or the next cell down, but right now its pasting the exact same value as in the first coordinate
sleep, 2000
started := True
} Else If started
Return
}
}
return
Re: Copy cells from CSV and Pasting into chrome
Posted: 23 Jun 2021, 09:17
by mikeyww
I think it will help if you can provide a sample CSV file, and then provide an example of exactly what the script should do, step by step.
Re: Copy cells from CSV and Pasting into chrome
Posted: 23 Jun 2021, 11:23
by rolo6464
mikeyww wrote: ↑23 Jun 2021, 09:17
I think it will help if you can provide a sample CSV file, and then provide an example of exactly what the script should do, step by step.
attached is an example, just a basic 2 column file with dates, the example only has 4 rows but real one will be a lot longer, but exact same thing
Re: Copy cells from CSV and Pasting into chrome
Posted: 23 Jun 2021, 14:25
by mikeyww
You have two different sets of coordinates. Should the script be alternating between them?
Re: Copy cells from CSV and Pasting into chrome
Posted: 23 Jun 2021, 14:58
by rolo6464
mikeyww wrote: ↑23 Jun 2021, 14:25
You have two different sets of coordinates. Should the script be alternating between them?
yeah exactly Column A is coordinate 1 and Column B is coordinate 2. Alternatively I could shove all the dates into 1 column (column A) but it would still have to alternate coordinates, So A1 is coordinate 1 and A2 is coordinate 2, A3 is coordinate 1 and A4 is coordinate 2. and so on.
Re: Copy cells from CSV and Pasting into chrome
Posted: 23 Jun 2021, 15:22
by mikeyww
I'm not sure if this helps, but this seems to accomplish your goal.
Code: Select all
coord := [[384, 254], [145, 254]]
Loop, Read, %A_ScriptDir%\test.csv ; Read each line of the CSV file
Loop, Parse, A_LoopReadLine, CSV ; Parse one CSV line
{ MouseClick,, coord.1.1, coord.1.2 ; Click on first set of coordinates
Send %A_LoopField% ; Send the first date on the line
coord.Push(coord.RemoveAt(1)) ; Move the first set of coordinates to the end of the set
Break ; Skip the rest of the line
}
If you do not like the array as a concept or tool here, you could just change the MouseClick to an alternating sequence if you like. You could use a variable to track which set of coordinates should be used.
Re: Copy cells from CSV and Pasting into chrome
Posted: 23 Jun 2021, 19:09
by rolo6464
mikeyww wrote: ↑23 Jun 2021, 15:22
I'm not sure if this helps, but this seems to accomplish your goal.
Code: Select all
coord := [[384, 254], [145, 254]]
Loop, Read, %A_ScriptDir%\test.csv ; Read each line of the CSV file
Loop, Parse, A_LoopReadLine, CSV ; Parse one CSV line
{ MouseClick,, coord.1.1, coord.1.2 ; Click on first set of coordinates
Send %A_LoopField% ; Send the first date on the line
coord.Push(coord.RemoveAt(1)) ; Move the first set of coordinates to the end of the set
Break ; Skip the rest of the line
}
If you do not like the array as a concept or tool here, you could just change the MouseClick to an alternating sequence if you like. You could use a variable to track which set of coordinates should be used.
This doesnt work for me, it feels like a step back because after the first date is entered it just stops
Isn't it possible to maybe refer to 2 different csv files and just call the first coordinate loopfield1 and then loopfield2 for the second coordinate. Problem is I don't understand what is what. Something like this below...
Code: Select all
file = C:\1.HardDrive\test.csv
file2 = C:\1.HardDrive\test2.csv
started := False
Loop, Read, %file%
{ Loop, Parse, A_LoopReadLine, CSV ; what is A_loopreadLine
{ If (A_Index != 1)
Continue
If A_LoopField {
MouseClick, left, 237, 684 ;<-- coordinate 1
Send %A_LoopField% ; csv file 1
sleep, 2000
MouseClick, left, 408, 684 ;<--- coordinate 2
Send %A_LoopField2% ;<---how to do I get this to reference csv file 2
sleep, 2000
started := True
} Else If started
Return
}
}
return
Re: Copy cells from CSV and Pasting into chrome
Posted: 23 Jun 2021, 19:20
by mikeyww
You haven't provided a clear description of exactly what should happen. I think that the scripts have met what you did describe. Instead of debugging and going through them line by line, you seem to want to just put them aside and try the next thing-- but I also do not know what the next thing is. It might help to step back and see what you really need. If you insert some "debugging" lines in the scripts to see what is happening step by step, it may also help you to see where any of the scripts might be going wrong. An alternative could be providing a simple description, step by step, of what should happen: "First, click on __, __, and insert text ____; second, click on ___, ___ and insert text ___", and so on. Perhaps you want others to step in at this point, since I have not had a lot of luck here! I actually do not understand your need well, as it seems that the script is just clicking at the same place and then sending different text each time-- so I do not get it, unfortunately. Sorry about that.
Re: Copy cells from CSV and Pasting into chrome
Posted: 23 Jun 2021, 19:41
by rolo6464
mikeyww wrote: ↑23 Jun 2021, 19:20
You haven't provided a clear description of exactly what should happen. I think that the scripts have met what you did describe. Instead of debugging and going through them line by line, you seem to want to just put them aside and try the next thing-- but I also do not know what the next thing is. It might help to step back and see what you really need. If you insert some "debugging" lines in the scripts to see what is happening step by step, it may also help you to see where any of the scripts might be going wrong. An alternative could be providing a simple description, step by step, of what should happen: "First, click on __, __, and insert text ____; second, click on ___, ___ and insert text ___", and so on. Perhaps you want others to step in at this point, since I have not had a lot of luck here! I actually do not understand your need well, as it seems that the script is just clicking at the same place and then sending different text each time-- so I do not get it, unfortunately. Sorry about that.
Sorry I thought I had explained what I needed but basically its this in a loop:
Mouseclick on coordinate 1
paste Data from Cell A1
Mouseclick on coordinate 2
paste Data from Cell B1
then does a set of procedures to long to paste here
repeat loop:...
Mouseclick on coordinate 1
paste Data from Cell A2
Mouseclick on coordinate 2
paste Data from Cell B2
then does a set of procedures to long to paste here
repeat loop:...
Mouseclick on coordinate 1
paste Data from Cell A3
Mouseclick on coordinate 2
paste Data from Cell B3
then does a set of procedures to long to paste here
See how the list runs down column A and B, basically it just keeps going until there's nothing left to paste in. Does that make sense?
Re: Copy cells from CSV and Pasting into chrome
Posted: 23 Jun 2021, 20:02
by mikeyww
Sure. When you test the first script that I posted, is it doing something different?
With a small change to display activity a bit:
Code: Select all
coord := [[384, 254], [145, 254]]
Loop, Read, %A_ScriptDir%\test.csv
Loop, Parse, A_LoopReadLine, CSV
{ Send % coord[A_Index].1 " " coord[A_Index].2 "`n"
Send %A_LoopField%`n
}
Output:
384 254
01012020
145 254
10222019
384 254
10222019
145 254
10222018
384 254
10222018
145 254
01022021
384 254
10222017
145 254
01012020
As far as I can tell, this matches what you wrote.
Re: Copy cells from CSV and Pasting into chrome
Posted: 23 Jun 2021, 20:11
by rolo6464
mikeyww wrote: ↑23 Jun 2021, 20:02
Sure. When you test the first script that I posted, is it doing something different?
With a small change to display activity a bit:
Code: Select all
coord := [[384, 254], [145, 254]]
Loop, Read, %A_ScriptDir%\test.csv
Loop, Parse, A_LoopReadLine, CSV
{ Send % coord[A_Index].1 " " coord[A_Index].2 "`n"
Send %A_LoopField%`n
}
Output:
384 254
01012020
145 254
10222019
384 254
10222019
145 254
10222018
384 254
10222018
145 254
01022021
384 254
10222017
145 254
01012020
As far as I can tell, this matches what you wrote.
I pasted that exactly and I got " the following variable name contains an illegal character: "coord[A-Index].1"
not sure which part is incorrect in that line
Re: Copy cells from CSV and Pasting into chrome
Posted: 23 Jun 2021, 20:16
by rolo6464
mikeyww wrote: ↑23 Jun 2021, 20:02
Sure. When you test the first script that I posted, is it doing something different?
With a small change to display activity a bit:
Code: Select all
coord := [[384, 254], [145, 254]]
Loop, Read, %A_ScriptDir%\test.csv
Loop, Parse, A_LoopReadLine, CSV
{ Send % coord[A_Index].1 " " coord[A_Index].2 "`n"
Send %A_LoopField%`n
}
Output:
384 254
01012020
145 254
10222019
384 254
10222019
145 254
10222018
384 254
10222018
145 254
01022021
384 254
10222017
145 254
01012020
As far as I can tell, this matches what you wrote.
I think it was just the % sign. Anyways it seems to just be typing out the coordinate?
The coorindate is basically a mouslick at a certain point in a page, like this:
MouseClick, left, 237, 684 <-- that is coordinate 1, its basically a click a certain coordiante
MouseClick, left, 405, 684 <-- that is coordinate 2, its basically a click a certain coordiante
Re: Copy cells from CSV and Pasting into chrome
Posted: 23 Jun 2021, 21:08
by mikeyww
You mean like the first script that I posted? When you run that first script, what does it actually do? Is your target window already active when you run the script? Remember that coordinates are relative to the active window. Are you running the script from a command line when Chrome is already active?
Re: Copy cells from CSV and Pasting into chrome
Posted: 23 Jun 2021, 21:37
by rolo6464
Yes that's correct, I already have chrome open and ready to play the script
Re: Copy cells from CSV and Pasting into chrome
Posted: 23 Jun 2021, 21:42
by rolo6464
So i took your first script and created the below but now its saying illegal character in the coord[A_Index].1 line. not sure why as It's exactly what you posted earlier.
Code: Select all
coord := [[237, 684], [408, 684]]
Loop, Read, C:\1.HardDrive\test.csv
Loop, Parse, A_LoopReadLine, CSV
{ MouseClick,, coord[A_Index].1, coord[A_Index].2,
Send %A_LoopField%
}
Re: Copy cells from CSV and Pasting into chrome
Posted: 23 Jun 2021, 21:49
by gregster
I pasted that exactly and I got " the following variable name contains an illegal character: "coord[A-Index].1"
Your
reported (and similar) error above shows a hyphen as part of a variable name
coord[A-Index].1 which I can't see anywhere in mikeyww's code.
- versus
_
But I don't see why you would get that error for this line.
Which AHK version are you running ?
Re: Copy cells from CSV and Pasting into chrome
Posted: 23 Jun 2021, 22:06
by rolo6464
version 1.0.48.05