Applescript 无法打开数字文件中的工作表

问题描述 投票:0回答:1

我是 Applescripts 新手,正在尝试打开 Numbers 文件以进行进一步处理。然而,我一生都无法让它打开一张纸。我的脚本如下,我已经验证具有该名称的工作表确实存在。我收到的错误消息是:


Please check the sheet name and try again.

完整代码如下:

-- Specify document path and other details
set documentPath to "/Users/uday/Downloads/tmm.numbers" -- Replace with actual path
set sheetName to "elo"
set rangeString to "A2:E3"

-- Initialize error flag
set hasError to false

-- Open the document
try
    tell application "Numbers"
        tell document documentPath
            -- Check if sheet exists
            if not (exists sheet sheetName) then
                display dialog "Sheet \"" & sheetName & "\" not found in the document." & return & return & "Please check the sheet name and try again." buttons {"OK"} default button 1
                set hasError to true
            else
                tell sheet sheetName
                    -- Check if range exists
                    try
                        set rangeToCheck to range rangeString
                    on error error_message number error_number
                        display dialog "Error accessing range \"" & rangeString & "\":" & return & error_message buttons {"OK"} default button 1
                        set hasError to true
                    end try
                end tell
            end if
        end tell
    end tell
on error error_message number error_number
    display dialog "Error opening document \"" & documentPath & "\":" & return & error_message buttons {"OK"} default button 1
    set hasError to true
end try

-- Continue with your script if no errors occurred
if not hasError then
    -- Do something with the document, sheet, or range
    display dialog "Document, sheet, and range accessed successfully!" buttons {"OK"} default button 1
end if
macos applescript
1个回答
0
投票

document
的参数可以是索引,也可以是文档的名称(标题栏中的字符串)。

要打开文档,您必须调用

open
并强制将 POSIX 路径强制为通用“class Furl”

然后通过索引访问前面的文档

-- Open the document
try
    tell application "Numbers"
        open documentPath as «class furl»
        tell document 1
            -- Check if sheet exists
© www.soinside.com 2019 - 2024. All rights reserved.