【问题标题】:How can I export a single Excel sheet to a PDF file using Applescript?如何使用 Applescript 将单个 Excel 工作表导出为 PDF 文件?
【发布时间】:2017-01-30 07:05:25
【问题描述】:

这是我正在使用的代码:

saveExcelasPDF("Users:Seth:Documents:OneDrive:Process:12648 0920 Volvo of the Triad 128.xlsx", "Users:Seth:Desktop:test.pdf")

    on saveExcelasPDF(documentPath, PDFName)
        set tFile to (POSIX path of documentPath) as POSIX file
        tell application "/Applications/Microsoft Excel.app"
            set isRun to running
            set wkbk1 to open workbook workbook file name documentPath
            activate object worksheet "Invoice" of wkbk1
            set mySheet to sheet "Invoice" of wkbk1
            alias PDFName -- Necessary to avoid Excel Sandboxing
            save mySheet in PDFName as PDF file format
            close wkbk1 saving no
            if not isRun then quit
        end tell
    end saveExcelasPDF

现在,它将所需书籍中的每张纸保存到 PDF 文件中,所以我最终得到了一个大约 60 页的 PDF..

如何仅将“发票”表保存到我的 PDF 文件中?

谢谢!

【问题讨论】:

    标签: excel macos pdf applescript


    【解决方案1】:

    这是PDF file format 的一个错误。

    CSV file format格式为例,save命令可以正常工作。

    解决方法是: 将工作表复制到新工作簿。

    on saveExcelasPDF(documentPath, PDFName)
        set tFile to (POSIX path of documentPath) as POSIX file
        tell application "/Applications/Microsoft Excel.app"
            set isRun to running
            set wkbk1 to open workbook workbook file name documentPath
            set newWBK to make new workbook
            copy worksheet (sheet "Invoice" of wkbk1) before sheet 1 of newWBK
            close wkbk1 saving no
            alias PDFName -- Necessary to avoid Excel Sandboxing
            save (sheet 1 of newWBK) in PDFName as PDF file format
            close newWBK saving no
            if not isRun then quit
        end tell
    end saveExcelasPDF
    

    【讨论】:

      猜你喜欢
      • 2017-03-21
      • 2016-12-06
      • 2021-04-22
      • 1970-01-01
      • 2016-12-09
      • 2020-06-27
      • 1970-01-01
      • 1970-01-01
      • 2016-08-04
      相关资源
      最近更新 更多