【问题标题】:Convert Excel to PDF using Applescript (save as PDF)使用 Applescript 将 Excel 转换为 PDF(另存为 PDF)
【发布时间】:2016-07-16 17:46:14
【问题描述】:

我有一个 .xlsx 文件,我想使用 Applescript 将其保存为 PDF 格式。我已经彻底搜索了这个,但显然有一百万个问题。

我想保存为 .app,其中代码中的 ... 将替换为代码块,以将活动工作簿转换为 PDF,如下所示:

tell application "Microsoft Excel"
    activate
    open  "/somedirectory/workbook1.xlsx"
    ...
end tell

【问题讨论】:

    标签: excel macos pdf applescript


    【解决方案1】:

    找到了!答案如下:

    http://blog.krugazor.eu/2010/01/applescript-batch-saving-to-pdf/

    以下内容来自以上链接:

    “基本上,它所做的是模拟击键和点击。这使您可以做任何用户能够做的事情。

    事不宜迟,AppleScript使用打印对话框将一堆excel文件批量保存为pdf!”

    on open some_items
        repeat with this_item in some_items
            try
                tell application "Microsoft Excel"
                    activate
                    open this_item
                    tell application "System Events" to tell process "Microsoft Excel"
                        --Bring up print window
                        keystroke "p" using command down
                        --Choose "PDF" > "Save as PDF"
                        click (menu button "PDF" of window 1)
                        click (menu item 1 of menu of menu button "PDF" of window 1)
                        delay 2
                        -- Choose the desktop as save locaton (Command-D)
                        keystroke "d" using command down
                        --Save
                        keystroke "s" using command down
                        keystroke return
    
                        -- wait and close
                        delay 3
                        keystroke "w" using command down
                    end tell
                end tell
            end try
        end repeat
    
        tell application "Finder"
            open desktop
        end tell
    end open
    

    【讨论】:

    • 对于后代,您能否在您的答案中包含您认为有用的链接的相关部分?这样,如果链接断开、更改等,您的答案不会变得无用。非常感谢。
    猜你喜欢
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    • 2017-03-21
    • 2011-05-26
    • 2017-01-13
    • 2018-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多