2016-09-21 77 views
0

這裏是我一起工作的代碼:眼下如何使用Applescript將單個Excel工作表導出爲PDF文件?

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文件中?

謝謝!

回答

0

這是一個錯誤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 
相關問題