2017-09-14 1 views
0

Ich suche Hilfe mit AppleScript (und beschränkt auf AppleScript aus beruflichen Gründen leider). Insbesondere kann ich nicht herausfinden, wie Excel-Spalten durchlaufen werden, während jede Zelle in dieser Spalte kopiert und eingefügt wird.Applescript, Schleife durch die Spalte (bis leer), kopieren und in Webformular einfügen

Hier ist, was ich bisher zu tun haben:

to clickID(theId) -- clickID function start 
    tell application "Safari" 
    do JavaScript "document.getElementById('" & theId & "').click();" in document 1 
    end tell 
end clickID 
--__________________________________________ 
tell application "Microsoft Excel" 
    activate 
    open "Filepath/Starfox Tester.xlsx" --changed filename for privacy 
    get active workbook 
    select cell "A2" --Headers will be in column A1, hence why selecting A2 
    tell application "System Events" to tell process "Microsoft Excel" to keystroke "c" using command down 
end tell 

do shell script "open -a Safari 'https://google.com'" 
    delay 2 --for website to load 
    clickID("lst-ib") 
    tell application "System Events" to tell process "Safari" to keystroke "v" using command down 

Bisher dies funktioniert; Ich verstehe, wie man es manuell macht, aber da meine Spalten jedes Mal eine andere Anzahl von Zeilen haben, wenn ich dieses Skript ausführe, muss es in der Lage sein, eine Schleife zu machen, bis es eine leere Zelle findet.

Jede Hilfe wäre sehr willkommen! Vielen Dank!

UPDATE: Ich denke, der einfachste Weg, es zu tun, könnte eine if-else-Schleife sein. Meine Grundidee ist, den a-Handler (Funktion) auszuführen, wenn die Zelle in der Referenz nicht leer ist. Da ich wahrscheinlich nicht mehr als 50 Zellen haben werde, plane ich nur das in (A1 - A50) hart zu codieren und den Handler jedes Mal auszuführen.

Ich versuche derzeit herauszufinden, wie der Handler zu programmieren. Hier ist, was ich bisher:

to populateVal(cellValue) 
    tell application "Microsoft Excel" 
    get active workbook 
    select cellValue 
    tell application "System Events" to tell process "Microsoft Excel" to keystroke "c" using command down 
     activate Safari 
     clickID("lst-ib") 
     tell application "System Events" to tell process "Safari" to keystroke "c" using command down 
    end tell 
end populateVal 

do shell script "open -a Safari 'https://google.com'" 

tell application "Microsoft Excel" 
activate 
open "Filepath/Starfox Tester.xlsx" 

    if cell "A2" ≠ "" then 
    populateVal("A2") 
    else 
    display dialog "Done!" 
    end if 

end tell 

Ich bin zurzeit ein Fehler immer sagen, dass Excel „kann populateVal nicht fortgesetzt werden“. Wenn ich die Klammer um A2 wegnehme, bekomme ich eine Fehlermeldung, dass A2 "nicht definiert ist". Jede Hilfe wäre willkommen!

Antwort

0

Nach etwas Basteln, kam ich unten mit einer funktionierenden Lösung.

on selectVal(cellValue) 
tell application "Microsoft Excel" 
    activate 
    get active workbook 
    select cell cellValue 
    tell application "System Events" to tell process "Microsoft Excel" to keystroke "c" using command down 
    delay 0.5 
    tell application "System Events" to tell process "Microsoft Excel" 
     key code 124 
    end tell 
    tell application "Safari" 
     activate 
     my clickID("lst-ib") 
     tell application "System Events" to tell process "Safari" to keystroke "v" using command down 
    end tell 
end tell 
end selectVal 
---- 

do shell script "open -a Safari 'https://google.com'" 
delay 2 --for website to load 

tell application "Microsoft Excel" 
open "Filepath/Starfox Tester.xlsx" 
end tell 

selectVal("A2") 
delay 1.5 
selectVal("B2") 
delay 1.5 

Im Grunde habe ich einen Handler/Funktion einen Wert zu kopieren, manuell in die nächste Zelle gehen, und führen Sie eine bestimmte Aktion auf der Webseite. Mein Denkprozess dahinter ist: Baue einen Handler, der an einer einzelnen Datenzeile arbeitet (ich habe Spalten gesetzt, aber variable Zeilen), dann rufe ich diesen Handler für jede Datenzeile, beginnend mit A2, einfach auf B. B2, C2 usw. und führen eine bestimmte Aktion mit dem Wert dieser Zelle aus (Webseite ist statisch).

Ich hoffe, das kann Ihnen helfen.

Verwandte Themen