Convert Excel to PDF using JavaScript

后端 未结 2 1364
终归单人心
终归单人心 2021-01-17 07:00

How can I convert Excel documents (files) to PDF in an automated fashion? I am trying to adapt the solution found here to Excel. So far I have this:

var fso          


        
相关标签:
2条回答
  • 2021-01-17 07:24

    You're clobbering objExcel on line 15:

    var objExcel = objExcel.Workbooks.Open(docPath);
    

    Those lines of code need to use a different variable, e.g.:

    var objWorkbook = objExcel.Workbooks.Open(docPath);
    
    var wdFormatPdf = 57;
    objWorkbook.SaveAs(pdfPath, wdFormatPdf);
    objWorkbook.Close();
    
    0 讨论(0)
  • 2021-01-17 07:33

    Try to use .ExportAsFixedFormat property instead of .SaveAs. First one is suitable for creating PDF files in Excel but not SaveAs which doesn't support PDF format.

    I guess you would need something like this:

    objExcel.ExportAsFixedFormat(0, pdfPath)
    
    0 讨论(0)
提交回复
热议问题