-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathgetExcels.ahk
51 lines (40 loc) · 1.43 KB
/
getExcels.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
; https://www.autohotkey.com/boards/viewtopic.php?p=463899#p463899
LookForDate := "5/22/2022"
LookForName := "EDUJHEVJ"
FilePath := A_ScriptDir "\testfile123.xlsx"
array := getXcells(FilePath, "sheet1") ; probably "blad1" in Dutch
for x,y in array
if (y.1 = LookForName and y.2 = LookForDate) ; adjust to your need A = 1 D = 4 and F = 6
msgbox % y.1 " " y.2 " " y.3 ; adjust to your need A = 1 D = 4 and F = 6
return
*/
getXcells(datasource, sheet := "sheet1") } { ; requires https://www.microsoft.com/en-us/download/details.aspx?id=54920
global colcnt, rowcnt
arr := [], rowcnt := 0
objConnection := ComObjCreate("ADODB.Connection"), objRecordSet := ComObjCreate("ADODB.Recordset")
try objConnection.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" . dataSource . "; Extended Properties='Excel 12.0 xml;HDR=no;IMEX=1';")
catch {
msgbox,48,, Error! Data could not be retrieved, 2
return
}
try objRecordset.Open("Select * FROM [" Sheet "$]", objConnection, 3, 3, 1) ; adOpenStatic = 3 , adLockOptimistic = 3 , adCmdText = 1
catch {
msgbox,48,, Error! %Sheet% does not exist, 2
return
}
pFields := objRecordset.Fields
while !objRecordset.EOF {
row := [], ++rowcnt
Loop, % colcnt := pFields.Count
row[A_Index] := pFields.Item(A_Index-1).value
arr.push(row)
objRecordset.MoveNext
}
objRecordSet.Close()
objConnection.Close()
objRecordSet := ""
objConnection := ""
return arr
}