如何使用applescript在后台读取excel数据

如何使用applescript在后台读取excel数据,excel,applescript,Excel,Applescript,使用下面的代码,我打开并读取excel数据,但文件在UI中被打开 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:Data

使用下面的代码,我打开并读取excel数据,但文件在UI中被打开

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
我想在后台打开这个文件,数据应该在后台读取,应该有任何与excel的UI界面,所有事情都应该在后台发生

Excel版本=11,
O.S MAC=10.9

我没有尝试这个,但下面是我如何编写代码的

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

谢谢你的关注。但我在第二次运行脚本时出错,错误如下。错误Microsoft Excel出错:AppleeEvent处理程序失败。数字-10000我测试了它,多次运行都没有发现任何错误。它按预期工作。你得弄清楚你那边发生了什么。嗨…请重播。我找到了确切的原因,如果我们关闭了excel从部队退出任务栏,然后它是上面显示的错误。但解决方案对我有效,谢谢你们宝贵的支持。真的,它解决了我的大问题。再次感谢。我很高兴它起作用了。请勾选我的答案作为您问题的答案,以便其他人知道您得到了帮助。