这是将复制的 Excel 数据放入数组的示例。
MyClipBoard=%ClipBoard% ; Remove any non-text (format) data
Loop, parse, MyClipBoard, `n,`r ; Place Excel content from clipboard in 2 dimentional Array
{ ; Start-Loop Read through each Line (record) in the ClipBoard data from Excel
FullRecord:=A_LoopField ; Put a whole row in the variable FullRecord
RecordNumber:=A_Index ; Store the current record (row) number.
Loop, parse, FullRecord, %A_Tab% ; Parse the row content (FullRecord) in separate fields
{ ; Start-Loop Read through each Field in the ClipBoard data from Excel
FieldNumber:=A_Index ; Store the current Field number.
Array%RecordNumber%_%FieldNumber% := A_LoopField ; Array1_1 is Excel Row 1 column A, Array1_2 = Excel Row 1 column B
} ; End-Loop Read through each Field in the ClipBoard data from Excel
} ; End-Loop Read through each Line (record) in the ClipBoard data from Excel
如果您需要更多示例来帮助您前进,请告诉我。
好的,这里有更多示例,您可以通过查看其他答案中的示例来清理它,例如使用 Variable++ 而不是 Variable +=1
; Read data from text file into one dimentional Array
ArrayCount = 0
Loop, Read, %A_ScriptDir%\SearchTerms.txt ; This loop retrieves each line from the file, one at a time.
{
ArrayCount += 1 ; Keep track of how many items are in the array.
Array%ArrayCount% := A_LoopReadLine ; Store this line in the next array element.
}
TextCounter = 1
IniWrite, %TextCounter%, C:\Temp\SearchTerms.ini, Counter, Nr ; Write counter in ini so I can restart at latest counter
SearchText:= Array1 ; Put data from Array1 into variable SearchText
MouseClick, left
Send, %SearchText%{Enter}
SplashTextOn, 200, 20,Searchterm,F%TextCounter% %SearchText%
WinMove, Searchterm, , , 0
Return
Browser_Favorites::
IniRead, TextCounter, C:\Temp\SearchTerms.ini, Counter, Nr ; Read latest counter
TextCounter += 1
IniWrite, %TextCounter%, C:\Temp\SearchTerms.ini, Counter, Nr
SearchText:=Array%TextCounter% ; Put data from Array+number into variable SearchText
; Examples with Array of 2 deep.
MyClipBoard=%ClipBoard% ; Remove any non-text (format) data
Loop, parse, MyClipBoard, `n,`r ; Place Excel content from clipboard in 2 dimentional Array
{ ; Start-Loop Read through each Line (record) in the ClipBoard data from Excel
FullRecord:=A_LoopField ; Put a whole row in the variable FullRecord
RecordNumber:=A_Index ; Store the current record (row) number.
Loop, parse, FullRecord, %A_Tab% ; Parse the row content (FullRecord) in separate fields
{ ; Start-Loop Read through each Field in the ClipBoard data from Excel
FieldNumber:=A_Index ; Store the current Field number.
Array%RecordNumber%_%FieldNumber% := A_LoopField ; Array1_1 is Excel Row 1 column A, Array1_2 = Excel Row 1 column B
} ; End-Loop Read through each Field in the ClipBoard data from Excel
} ; End-Loop Read through each Line (record) in the ClipBoard data from Excel
DLCounter:=1
DLSub:=1
DLData:=Array%DLCounter%_1
While (DLData <> "")
{
While (DLData <> "")
{
MsgBox, %DLData%
DLSub += 1
DLData:=Array%DLCounter%_%DLSub%
}
DLSub:=1
DLCounter += 1
DLData:=Array%DLCounter%_%DLSub%
}
Return
它可能不是最干净的代码,但它会让你知道你能做什么。