/ / AppleScript Conta e rimuovi caratteri in Excel: excel, count, applescript

AppleScript conta e rimuove i caratteri in Excel: excel, conteggio, meleScript

Sto avendo problemi con il mio AppleScriptrimuove qualsiasi nome di file di lunghezza superiore a 13 caratteri. Ho una lista di nomi di file nella colonna B e ho solo bisogno di quelli che sono 13 caratteri, nient'altro che. Sto cercando la sceneggiatura per cancellare la riga di qualcosa di più di 13. Finora questo è stato un po 'funzionante e non li ha rimossi.

        tell application "Microsoft Excel"
activate
open (choose file with prompt "Select the Excel file you wish to use.")
end tell


tell application "Microsoft Excel"
tell active sheet
autofit column "A:H"
end tell
end tell

set cellNumber to 2

tell application "Microsoft Excel"
activate
repeat
set fileName to get value of cell ("B" & cellNumber) as string
set fncount to count characters of fileName
if fncount is greater than 13 then
delete entire row of cell ("B" & cellNumber)
set endCount to 0
else
set endCount to endCount + 1
if endCount > 100 then
exit repeat
end if
end if
set cellNumber to cellNumber + 1
end repeat
end tell
set endCount to 0

risposte:

0 per risposta № 1

Questo non cancella tutto, perché quando lo script cancella una riga, Eccellere sposterà le file verso l'alto.

Esempio: lo script cancella la seconda riga, ora la seconda riga è la terza riga, quindi lo script salta una riga

Per evitare ciò, il ciclo deve iniziare all'indice dell'ultima riga.

Usa il used range proprietà per ottenere l'ultima riga.

tell application "Microsoft Excel"
activate
open (choose file with prompt "Select the Excel file you wish to use.")
tell active sheet
set cellNumber to 2
autofit column "A:H"
set lastR to count rows of used range -- get the index of the last row which contains a value
repeat with i from lastR to cellNumber by -1 --  iterates backwards from the index of the last row
set fileName to string value of cell ("B" & i)
if (count fileName) > 13 then delete row i
end repeat
end tell
end tell