Applescript Excel 2016 save as PDF

后端 未结 2 1147
北恋
北恋 2021-01-21 10:24

I am trying to save an Excel 2016 spreadsheet as a PDF file. I have following simple Applescript that is called from within an Objective C program:

on saveExcel         


        
2条回答
  •  时光说笑
    2021-01-21 10:57

    Here's a script for Excel 2016 (version 15.22).

    I've added comments in the script:

    on saveExcelAsPDF(documentPath, PDFPath) -- params = two HFS paths
        set tFile to (POSIX path of documentPath) as POSIX file -- get a posix file object to avoid grant access issue with 'Microsoft Office 2016',  not the same as (file documentPath) when using the 'open  ...' command
    
        tell application "Microsoft Excel"
            set isRun to running
            set wkbk1 to open workbook workbook file name tFile
            alias PDFPath -- This is necessary to any script for 'Microsoft Office 2016', this avoid errors with any "save ... " command
            save workbook as wkbk1 filename PDFPath file format PDF file format with overwrite
            close wkbk1 saving no
            if not isRun then quit
        end tell
    end saveExcelAsPDF
    

提交回复
热议问题