Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ParseCSV("C:\file.csv", "oField_*_*")
- Return
- ScrollLock::
- n++
- Clip(Field_%n%_1)
- Send {Tab}
- Clip(Field_%n%_2)
- Send {Tab}
- Clip(Field_%n%_3)
- Send {Tab}
- Send % Field_%n%_4
- Return
- ;============================================= Functions (Ignore this part) =============================================
- ParseCSV(File, Options="") ; http://www.autohotkey.com/community/viewtopic.php?t=78105
- {
- @5 := 1, Literal := """", Commands := "r|c|d|l|o|t|nl", Column := 1, Row := 1, Tolerance := 1
- ;---------------------------------OPTIONS:-----------------------------------------------------------
- ; DEFAULT USER DEFAULT NAME ABOUT
- , r := "All", r_user := "" ;r = Rows Rows to query. Use commas & dashes (e.g. 1,3,5-9) as in the windows "pages to print" dialog
- , c := "All", c_user := "" ;c = Columns Columns to query. Same format as above
- , d := ",", d_user := "`t" ;d = Delimiter Character that delimits cells
- , l := """", l_user := "'" ;l = Literal Character that indicates literal text
- , o := "", o_user := "Array_*_*" ;o = Output Array Name of output pseudoarray created using Global(). First asterisk is rows and second is columns
- , t := True, t_user := False ;t = Trim Trims the rightmost row if it is empty in all cells
- , nl := "`r`n", nl_user := "" ;nl = New Line Any of these characters will be considered a new line
- ;---------------------------------USER CONFIGURATIONS:-----------------------------------------------
- , UserConfig_Foo := "x12 y34"
- , UserConfig_Bar := "cWhite -a"
- ;----------------------------------------------------------------------------------------------------
- While (@5 := RegExMatch(Options, "i)(?:^|\s)(?:!(\w+)|(\+|-)?(" Commands ")(" Literal "(?:[^" Literal "]|" Literal Literal ")*" Literal "(?=\s|$)|\S*))", @, @5 + StrLen(@)))
- If (@1 <> "")
- Options := SubStr(Options, 1, @5 + StrLen(@)) UserConfig_%@1% SubStr(Options, @5 + StrLen(@))
- Else If (@4 <> "") {
- If (InStr(@4, Literal) = 1) and (@4 <> Literal) and (SubStr(@4, 0, 1) = Literal) and (@4 := SubStr(@4, 2, -1))
- StringReplace, @4, @4, %Literal%%Literal%, %Literal%, All
- %@3% := @4
- } Else
- %@3% := @2 = "+" ? True : @2 = "-" ? False : %@3%_user
- FileRead, File, % @ := File
- If ErrorLevel {
- MsgBox, 262160, %A_ScriptName% - %A_ThisFunc%(): Error, Could not read CSV file`n"%File%"
- Return
- }
- Loop, Parse, File
- {
- If PrimeRow
- If !(PrimeRow -= 1) {
- If !Widest or (Widest - Column <= Tolerance)
- Row += 1
- Column := 0, PrimeColumn := True
- } Else
- Continue
- If !InStr(nl, A_LoopField) or IsLiteral {
- If PrimeColumn
- Column += 1, PrimeColumn := False
- If (A_LoopField = l) {
- If (Previous = l)
- Array_%Row%_%Column% .= l
- IsLiteral := !IsLiteral
- } Else If (A_LoopField <> d) or IsLiteral
- Array_%Row%_%Column% .= A_LoopField
- Else If t
- PrimeColumn := True
- Else
- Column += 1
- If (Column > Widest)
- Widest := Column
- } Else If !InStr(nl, Previous)
- PrimeColumn := False, PrimeRow := 2
- Previous := A_LoopField
- }
- If (o <> "") {
- If !InStr(o, "*")
- o := o "_*_*"
- Loop %Row% {
- StringReplace, @, o, *, % ThisRow := A_Index
- Loop %Widest% {
- StringReplace, @@, @, *, %A_Index%
- Global(@@, Array_%ThisRow%_%A_Index%)
- }
- }
- }
- If (r <> "") or (c <> "") {
- r := Expand(!r or (r = "All") ? "1-" Row : SubStr(r, 0) = "-" ? r Row : r), c := Expand(!c or (c = "All") ? "1-" Widest : SubStr(c, 0) = "-" ? c Widest : c)
- Loop, Parse, r, `,
- {
- @ := A_LoopField
- Loop, Parse, c, `,
- Output .= "," CSV(Array_%@%_%A_LoopField%)
- }
- ErrorLevel := Row A_Space Widest
- Return SubStr(Output, 2)
- } Else
- Return Row A_Space Widest
- }
- Global(Var, Value)
- {
- Global
- %Var% := Value
- }
- Expand(Input)
- {
- Loop, Parse, Input, `,, %A_Tab%%A_Space%
- {
- StringSplit, Term, A_LoopField, -
- If ((Term1 <> "") + (Term2 <> "") + (Term3 <> "") + (Term4 <> "") > 1) {
- Loop 4
- If (Start <> "") {
- If (Term%A_Index% <> "") {
- End := A_Index = 4 ? -Term%A_Index% : Term%A_Index%
- Break
- }
- } Else If (Term%A_Index% <> "")
- Start := A_Index = 2 ? -Term%A_Index% : Term%A_Index%
- While (A_Index <= End - Start + 1)
- Output .= "," Start + A_Index - 1
- Term1 := "", Term2 := "", Term3 := "", Term4 := "", Start := ""
- } Else
- Output .= "," A_LoopField
- }
- Return SubStr(Output, 2)
- }
- CSV(Text, Delimiter=",", Literal="""")
- {
- If (InStr(Text, Literal) = 1) or InStr(Text, Delimiter) or InStr(Text, "`n") or InStr(Text, "`r") {
- StringReplace, Text, Text, %Literal%, %Literal%%Literal%, All
- Text := Literal Text Literal
- }
- Return Text
- }
- Clip(Text="", Reselect="") ; http://www.autohotkey.com/forum/viewtopic.php?p=467710 , modified February 19, 2013
- {
- Static BackUpClip, Stored, LastClip
- If (A_ThisLabel = A_ThisFunc) {
- If (Clipboard == LastClip)
- Clipboard := BackUpClip
- BackUpClip := LastClip := Stored := ""
- } Else {
- If !Stored {
- Stored := True
- BackUpClip := ClipboardAll ; ClipboardAll must be on its own line
- } Else
- SetTimer, %A_ThisFunc%, Off
- LongCopy := A_TickCount, Clipboard := "", LongCopy -= A_TickCount ; LongCopy gauges the amount of time it takes to empty the clipboard which can predict how long the subsequent clipwait will need
- If (Text = "") {
- SendInput, ^c
- ClipWait, LongCopy ? 0.6 : 0.2, True
- } Else {
- Clipboard := LastClip := Text
- ClipWait, 10
- SendInput, ^v
- }
- SetTimer, %A_ThisFunc%, -700
- Sleep 20 ; Short sleep in case Clip() is followed by more keystrokes such as {Enter}
- If (Text = "")
- Return LastClip := Clipboard
- Else If (ReSelect = True) or (Reselect and (StrLen(Text) < 3000)) {
- StringReplace, Text, Text, `r, , All
- SendInput, % "{Shift Down}{Left " StrLen(Text) "}{Shift Up}"
- }
- }
- Return
- Clip:
- Return Clip()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement