2017-05-03 1 views
0

길이가 13 자보다 긴 모든 파일 이름을 제거하는 내 AppleScript에 문제가 있습니다. B 열에 파일 이름 목록이 있는데 13 문자 만 필요합니다. 나는 13 개 이상의 행을 지우는 스크립트를 찾고있다. 지금까지는 다소 효과가 있었지만 모두 제거하지는 않았다.AppleScript로 Excel에서 문자 수를 늘리고 제거하십시오

 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 

답변

0

이 모든 것을 삭제하지 않습니다, 스크립트가 행을 삭제할 때, 엑셀가 행을 이동 때문입니다.

: 스크립트 이제 두 번째 행이 가 세 번째 행이며, 두 번째 행을 삭제, 그래서 스크립트가

는 것을 방지하기 위해 행을 건너 뛰고, 루프 인덱스에서 시작해야합니다 마지막 행의

used range 속성을 사용하면 마지막 행을 가져올 수 있습니다.

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 
+0

정말 고마워요! 그 트릭을 했어! –

관련 문제