/ / AppleScript Count e Remove Characters no Excel - excel, count, applescript

AppleScript Count e Remove Characters no Excel - excel, count, applescript

Estou tendo problemas com o meu applescript queremove qualquer nome de arquivo com mais de 13 caracteres. Eu tenho uma lista de nomes de arquivos na coluna B e eu só preciso dos que são 13 caracteres, nada mais que. Eu estou procurando o script para excluir a linha de qualquer coisa mais do que 13. Até agora isso tem sido um pouco de trabalho e não removendo todos eles.

        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

Respostas:

0 para resposta № 1

Isso não exclui tudo, porque quando o script excluir uma linha, Excel irá deslocar as linhas para cima.

Exemplo: o script exclui a segunda linha, agora a segunda linha é a terceira linha, então o script pula uma linha

Para evitar isso, o loop deve começar no índice da última linha.

Use o used range propriedade para obter a última linha.

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