2014-10-06 2 views
0

다음 코드를 사용하여 Excel 데이터를 열어 읽는 중 UI에서 파일이 열립니다.applescript를 사용하여 백그라운드에서 데이터를 Excel에서 읽는 방법

set iRowNo to "A" 
set iCellCount to "2" 
set SheetName to "Sheet1" 
on ExcelFileReadingData(iRowNo, iCellCount, SheetName) 
    set xlsFilePath to (path to desktop as Unicode text) & "SofTestSmokeAutomationSuite:DataSheet.xlsx" as Unicode text 
    tell application "System Events" 
     tell application "Microsoft Excel" 
      tell worksheet SheetName 
       activate 
       open xlsFilePath 
       delay 2 
       set iCellValue to value of range ("" & iRowNo & "" & iCellCount) as text 
      end tell 
     end tell 
     tell application "System Events" 
      tell application process "Microsoft Excel" 
       click button 3 of window "DataSheet.xlsx" 
      end tell 
     end tell 
     return iCellValue 
    end tell 
end ExcelFileReadingData 

은 나뿐만 아니라 데이터가 백그라운드에서 읽을 얻을합니다 같은 배경에서이 파일을 열 때 모든 일이 백그라운드에서 수행되어야한다 엑셀 어떤 UI 인터페이스가 있어야합니다.

엑셀 버전 = 11, O.S MAC는 = 10.9

답변

0

나는 이것을 시도하지만, 여기에 내가 코드를 작성 할 방법은 없었다.

set iRowNo to "A" 
set iCellCount to "2" 
set SheetName to "Sheet1" 

ExcelFileReadingData(iRowNo, iCellCount, SheetName) 

on ExcelFileReadingData(iRowNo, iCellCount, SheetName) 
    -- open the file 
    set xlsFilePath to (path to desktop as text) & "SofTestSmokeAutomationSuite:DataSheet.xlsx" 
    tell application "Microsoft Excel" to open file xlsFilePath 
    delay 2 

    -- hide excel 
    tell application "System Events" 
     set excel to first process whose name is "Microsoft Excel" 
     set visible of excel to false 
    end tell 

    -- get the value 
    tell application "Microsoft Excel" 
     set iCellValue to (value of range (iRowNo & iCellCount) of worksheet SheetName of workbook 1) as text 
    end tell 

    return iCellValue 
end ExcelFileReadingData 
+0

감사합니다. 하지만 스크립트를 두 번째로 실행하면 오류가 발생합니다. 오류는 다음과 같습니다. – Girish

+0

오류 "Microsoft Excel에 오류가 발생했습니다 : AppleEvent 처리기가 실패했습니다." number -10000 – Girish

+0

테스트를 해본 결과 여러 번 오류가 발생하지 않습니다. 그것은 예상대로 작동합니다. 당신은 당신의 끝에서 일어나고있는 것을 알아 내야 할 것입니다. – regulus6633

관련 문제