how to read excel column and put it in array and send it

Get help with using AutoHotkey and its commands and hotkeys
mozart1000
Posts: 3
Joined: 23 May 2017, 19:48
Facebook: reza.i.nugraha

how to read excel column and put it in array and send it

23 May 2018, 11:13

Greeting I'd like to ask help from you guys
at the beginning i need to make my script to read and write bunch numeric data into another program
and then i googling there and there and make my own script
my script read CSV
i used to copy my data into excel column A and then i save as CSV and then my ahk program read and send it into another program
here's my script

Code: Select all

			Loop, read, C:\Users\Reza\Dropbox\Dispenda\Sulapan\Sulapan Jilid 3 Auto Reborn\%personel%\Status\%k%\%l%.csv
			{
				Loop, parse, A_LoopReadLine, CSV
				{
					Send, %A_LoopField%
					Send, `n
					sleep 1250
					Loop, 2
					{
						Send, `n
						sleep 150
					}
					if (l>=3)
					{	
						Send, 7
					}
					if (l<=2)
					{	
						Send, 0
					}
					Send, `n
					sleep 200
					Send, `n
					sleep 1250
				}
			}
the problem is right now my data now is expand not only 1 variable but 3
which is i need 3 column excel
i know i should move from csv into xls/xlsx and then read it
but i can't find how to read excel based on column
like put column A value excel into arrayA and then put column B value excel into arrayB and so on
i hope i don't make you guys get confused for my bad english
hope you guys can help me
thanks in advance
FanaticGuru
Posts: 1207
Joined: 30 Sep 2013, 22:25

Re: how to read excel column and put it in array and send it

23 May 2018, 12:33

Code: Select all

; Create a connection between AHK and an open active Excel file
xlApp := ComObjActive("Excel.Application")

Columns := ["A","D","F"]
Data := {}
; Get all cell values in columns and put in an array
for Index, Column in Columns
	for xlCell in xlApp.ActiveSheet.UsedRange.Columns(Column).Cells
		Data[Column, A_Index] := xlCell.Value

; Display second cell value from Column A
MsgBox % Data.A.2

; Display all the values in Column F
for Index, Value in Data.F
	Display .= Index "`t" Value "`n"
MsgBox % Display
This shows the basics of looping through the cells of a column.

There are alot of different ways the data could be arranged in the array. It is also unclear how you want to handle blank cells. If all columns are the same length. If you need to also store the row number or just a straight index.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts

AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon

[Function] Timer - Create and Manage Timers
mozart1000
Posts: 3
Joined: 23 May 2017, 19:48
Facebook: reza.i.nugraha

Re: how to read excel column and put it in array and send it

23 May 2018, 19:17

Thank you so much appreciate it fortunately my data don't have blank cell
for example here's my data
Column A Column B Column C
W 1234 AA
L 9876 ZZ
N 5555 XX
etc
mozart1000
Posts: 3
Joined: 23 May 2017, 19:48
Facebook: reza.i.nugraha

Re: how to read excel column and put it in array and send it

02 Jun 2018, 00:04

Btw Can i Read it as close excel file
since i've to read several excel file

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Drugwash, Google [Bot], Kellyzkorner_NJ, Sabestian Caine and 59 guests