Wie kann ich in einer Numbers-Datei basierend auf einer vordefinierten Hauptliste automatisch suchen und ersetzen?
Zum Beispiel möchte ich alle finden und ersetzen:
Ein paar Gedanken / Workflow-Erwartungen:
Ich bin mir nicht ganz sicher, wie Sie das Numbers- Dokument formatiert haben oder wie genau Sie die Master-Liste der Suchen & Ersetzen -Elemente speichern möchten oder wo, aber der folgende Beispiel - AppleScript- Code ist eingerichtet, um die Verwendung der Master-Liste von zu zeigen Suchen & Ersetzen von Elementen als einzelne Tabelle in einem Blatt im Numbers- Dokument und besteht aus zwei Spalten und beliebig vielen Zeilen, die Sie benötigen.
Die Abbildungen unten zeigen die Blätter , die Hauptliste der Suchen-und-Ersetzen- Elemente und das Vorher und Nachher von Blatt 1 . Die Daten sind einfach, aber unter dem Strich funktioniert es, um die Paare von Find & Replace -Elementen in der Masterliste schnell zu finden und zu ersetzen .
Dies wird so viel schneller sein als jeder manuelle Prozess, um dasselbe Ziel zu erreichen.
Beachten Sie, dass bei der Codierung davon ausgegangen wird, dass die Zellen keine Formeln enthalten und als Text formatiert sind.
Beispiel AppleScript -Code :
tell application "Numbers"
tell front document
-- # Get the Find & Replace list.
set theFindReplaceList to ¬
the formatted value of ¬
the cells of the rows 2 thru -1 of ¬
table "Find & Replace" of ¬
sheet "Master List" whose ¬
value is not missing value
-- # Clean up the List removing empty cells and rows
-- # so there are only pairs of find/replace items.
set theFindReplaceListItems to {}
repeat with aListItem in theFindReplaceList
if the length of aListItem is 2 then ¬
copy aListItem to the end of theFindReplaceListItems
end repeat
copy theFindReplaceListItems to theFindReplaceList
-- ### Find & Replace ###
if the name of active sheet is not "Master List" then
-- # For each table of the active sheet.
repeat with i from 1 to the count of the tables of the active sheet
-- # For each Find & Replace pair.
repeat with thisListItem in theFindReplaceList
-- # For every cell containing the FIND text.
set theReplaceCellsList to the (cells of table i of sheet 1 ¬
whose formatted value contains item 1 of thisListItem)
-- # Replace it with the REPLACE text.
-- # Uncomment 'considering case' and 'end considering'
-- # for case senstive find/replace operations.
--considering case
repeat with aCell in theReplaceCellsList
set the value of aCell to my findAndReplaceInCellValue(formatted value of aCell, ¬
item 1 of thisListItem, item 2 of thisListItem)
end repeat
--end considering
end repeat
end repeat
tell table 1 of active sheet to set selection range to range "A1"
end if
end tell
end tell
-- ## Handler ##
on findAndReplaceInCellValue(theFormatedCellValue, theFindValue, theReplaceValue)
set AppleScript's text item delimiters to theFindValue
set theTextItems to every text item of theFormatedCellValue
set AppleScript's text item delimiters to theReplaceValue
set theFormatedCellValue to theTextItems as string
set AppleScript's text item delimiters to ""
return theFormatedCellValue
end findAndReplaceInCellValue
Anmerkungen:
Während der codierte AppleScript- Beispielcode ein Blatt innerhalb des Zieldokuments für seine Suchen-und-Ersetzen- Elemente verwendet , kann er dennoch so codiert werden, dass er eine externe Quelle verwendet, z. B. ein anderes Numbers- Dokument .
In beiden Codebeispielen wird das Hauptlistenblatt von den Suchen/Ersetzen - Vorgängen nicht berührt.
Bei den Suchen/Ersetzen-Operationen wird die Groß-/Kleinschreibung nicht beachtet . Wenn Sie beim Suchen/Ersetzen zwischen Groß- und Kleinschreibung unterscheiden müssen , kommentieren Sie die Anweisungenconsidering case
und im AppleScript- Beispielcode aus .end considering
Wie codiert wirken sich die Suchen/Ersetzen-Operationen auf Zellen aus , die den Wert von FIND- Text und alles andere in der Zelle enthalten . Wenn Sie auf Zellen beschränken möchten, die nur den FIND- Text und nichts anderes enthalten, dann:
Ändern:
set theReplaceCellsList to the (cells of table i of aSheet ¬
whose formatted value contains item 1 of thisListItem)
Zu:
set theReplaceCellsList to the (cells of table i of aSheet ¬
whose formatted value is item 1 of thisListItem)
Der Beispiel- AppleScript- Code kann in einem Automator- Dienst/einer Schnellaktion mit einer Aktion „AppleScript ausführen“ verwendet und einem Tastenkürzel in „ Systemeinstellungen“ > „Tastatur “ > „Kurzbefehle “ > „ Dienste“ zugewiesen oder mit einer beliebigen Drittanbieteranwendung verwendet werden, die AppleScript- Skripts usw. ausführen kann
Beispiel AppleScript -Code :
tell application "Numbers"
tell front document
-- # Get the Find & Replace list.
set theFindReplaceList to ¬
the formatted value of ¬
the cells of the rows 2 thru -1 of ¬
table "Find & Replace" of ¬
sheet "Master List" whose ¬
value is not missing value
-- # Clean up the List removing empty cells and rows
-- # so there are only pairs of find/replace items.
set theFindReplaceListItems to {}
repeat with aListItem in theFindReplaceList
if the length of aListItem is 2 then ¬
copy aListItem to the end of theFindReplaceListItems
end repeat
copy theFindReplaceListItems to theFindReplaceList
-- ### Find & Replace ###
-- # For each sheet in the document.
repeat with aSheet in (sheets whose name is not "Master List")
-- # For each table of the sheet.
repeat with i from 1 to the count of the tables of aSheet
-- # For each Find & Replace pair.
repeat with thisListItem in theFindReplaceList
-- # For every cell containing the FIND text.
set theReplaceCellsList to the (cells of table i of aSheet ¬
whose formatted value contains item 1 of thisListItem)
-- # Replace it with the REPLACE text.
-- # Uncomment 'considering case' and 'end considering'
-- # for case senstive find/replace operations.
--considering case
repeat with aCell in theReplaceCellsList
set the value of aCell to my findAndReplaceInCellValue(formatted value of aCell, ¬
item 1 of thisListItem, item 2 of thisListItem)
end repeat
--end considering
end repeat
end repeat
tell table 1 of active sheet to set selection range to range "A1"
end repeat
end tell
end tell
-- ## Handler ##
on findAndReplaceInCellValue(theFormatedCellValue, theFindValue, theReplaceValue)
set AppleScript's text item delimiters to theFindValue
set theTextItems to every text item of theFormatedCellValue
set AppleScript's text item delimiters to theReplaceValue
set theFormatedCellValue to theTextItems as string
set AppleScript's text item delimiters to ""
return theFormatedCellValue
end findAndReplaceInCellValue
Die Suchen & Ersetzen -Tabelle muss immer aus zwei Spalten bestehen, das Skript ist jedoch so codiert, dass nur Zeilen verarbeitet werden , die sowohl ein Suchen- als auch ein Ersetzen- Element enthalten.
Hinweis: Der Beispiel- AppleScript- Code ist genau das und enthält abgesehen von der enthaltenen Fehlerbehandlung keine zusätzliche Fehlerbehandlung , die angemessen sein könnte. Es liegt in der Verantwortung des Benutzers, eine Fehlerbehandlung hinzuzufügen, die angemessen, erforderlich oder gewünscht ist. Sehen Sie sich die try- Anweisung und die error- Anweisung im AppleScript Language Guide an . Siehe auch Arbeiten mit Fehlern . Zusätzlich kann die Verwendung des Verzögerungsbefehls gegebenenfalls zwischen Ereignissen erforderlich sein, z. B. mitdelay 0.5
dem Wert der Verzögerungpassend einstellen.
Bisher habe ich das hier. Ich weiß, die Antwort ist unvollständig, aber Sie können sehen, ob dies der richtige Weg für Sie ist. Ich werde es bearbeiten, wenn ich es fertig habe.
Code:
on run {input, parameters}
tell application "Numbers"
activate
tell front document
tell sheet "Master" -- use info from master sheet
tell table 1
set FIND to value of cell "B2" as text
set REPLACE to value of cell "C2" as text
end tell
end tell
end tell
tell document 1 of application "Numbers"
set active sheet to sheet 1 -- work data from Sheet 1
end tell
end tell
tell application "System Events"
key code 3 using {command down} -- Command+F to search/replace
delay 0.15
set the clipboard to FIND
delay 3 -- enough time to perform search (should be tweaked for large documents)
key code 9 using {command down} -- paste data to find
delay 0.8
key code 48 -- tab
delay 0.8
set the clipboard to REPLACE
delay 0.8
key code 9 using {command down} -- paste data to replace
delay 0.8
key code 48 -- tab
delay 0.8
key code 49 -- space (press "replace all" button)
end tell
end run
Nächste Schritte:
Fahrrad