2016-09-21 39 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 
相关问题