ABAP EXCEL 转 PDF

DATA: application TYPE ole2_object,
workbook TYPE ole2_object,
sheet TYPE ole2_object.
IF iv_pdf IS NOT INITIAL.
CREATE OBJECT application ‘EXCEL.APPLICATION’.
CALL METHOD OF application ‘WORKBOOKS’ = workbook.
CALL METHOD OF workbook ‘OPEN’
EXPORTING
#1 = output_path_xlsx.
CALL METHOD OF application ‘WORKSHEETS’ = sheet
EXPORTING
#1 = 1. "Sheet1
CALL METHOD OF sheet ‘ACTIVATE’.

  output_path_pdf = output_path_xlsx.REPLACE '.xlsx' WITH '.pdf' INTO output_path_pdf.REPLACE '.XLSX' WITH '.pdf' INTO output_path_pdf.CALL METHOD OF sheet 'ExportAsFixedFormat'EXPORTING#1 = 0#2 = output_path_pdf.CALL METHOD OF workbook 'CLOSE'.CALL METHOD OF application 'QUIT'.FREE OBJECT: application,workbook,sheet.CALL METHOD cl_gui_frontend_services=>file_existEXPORTINGfile                 = output_path_pdfRECEIVINGresult               = DATA(l_res)EXCEPTIONScntl_error           = 1error_no_gui         = 2wrong_parameter      = 3not_supported_by_gui = 4OTHERS               = 5.IF sy-subrc <> 0 OR l_res = space.MESSAGE |PDF另存失败| TYPE 'E'.ELSE.MESSAGE |PDF另存为{ output_path_pdf }| TYPE 'S'.ENDIF.CALL METHOD cl_gui_frontend_services=>file_deleteEXPORTINGfilename             = output_path_xlsxCHANGINGrc                   = l_dummy_rcEXCEPTIONSfile_delete_failed   = 1cntl_error           = 2error_no_gui         = 3file_not_found       = 4access_denied        = 5unknown_error        = 6not_supported_by_gui = 7wrong_parameter      = 8OTHERS               = 9.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.
ENDIF.

ENDMETHOD.