OLE Excel 、Word 转换 pdf 文件

 以下是 OLE Word 转换 PDF 文件


1
DATA:gs_word TYPE ole2_object, 2 gs_docu TYPE ole2_object. 3 4 5 create OBJECT gs_word 'WORD.APPLICATION' . 6 CALL METHOD OF gs_word 'Documents' = gs_docu. 7 8 CALL METHOD OF gs_docu 'Open' = GS_docu 9 EXPORTING #1 = 'C:UsersitstudyDesktopaa.docx'. 10 11 CALL METHOD OF gs_docu 'ExportAsFixedFormat' = GS_docu 12 EXPORTING 13 #1 = 'C:UsersitstudyDesktopaa.pdf' 14 #2 = '17'. 15 CALL METHOD OF gs_word 'QUIT' .

原文出置:https://answers.sap.com/questions/11494117/abap---ole-ms-word-save-docx-as-pdf.html

以下是 OLE EXCEL 转换 PDF 文件

测试发现以下程序需要office激活和安装盘符才可以转换

REPORT y_excel_ole_pdf.
LOAD-OF-PROGRAM.
* Allow OLE calls to COM enabled programs on Workstation (e.g. Excel)
  INCLUDE ole2incl.
* handles for OLE objects
  DATA: oexcel           TYPE ole2_object,    " Excel object
        owbs             TYPE ole2_object,    " collection of workbooks
        owb              TYPE ole2_object.    " workbook
*&---------------------------------------------------------------------*
*&      Form  ErrorHandler
*&---------------------------------------------------------------------*
*       outputs OLE error if any was returned by SAP
*----------------------------------------------------------------------*
  FORM errorhandler.
    IF sy-subrc <> 0.
      WRITE: / 'OLE-Automation Error:'(010), sy-subrc.
      CALL METHOD OF oexcel 'Quit'.
      FREE OBJECT oexcel.
      STOP.
    ENDIF.
  ENDFORM.                    " ErrorHandler
  PARAMETERS: p_source TYPE string LOWER CASE.
  PARAMETERS: p_dest   TYPE string LOWER CASE.
START-OF-SELECTION.
* Start a new copy of Excel
  CREATE OBJECT oexcel 'EXCEL.APPLICATION'.
  PERFORM errorhandler.  "Set oExcel = CreateObject()
* Hide Excel window for now (faster)
  SET PROPERTY OF oexcel 'Visible' = 0.
  PERFORM errorhandler.  "oExcel.Visible = False
* Tell Excel not to update entire worksheet with each change (faster)
  SET PROPERTY OF oexcel 'ScreenUpdating' = 0.
  PERFORM errorhandler.  "oExcel.ScreenUpdating = False
* Get list of workbooks, initially empty
  CALL METHOD OF oexcel 'Workbooks' = owbs.
  PERFORM errorhandler.  "Set oWBs = oExcel.Workbooks
* Open excel file, returning workbook
  CALL METHOD OF owbs 'Open' "= owb
    EXPORTING #1 = p_source.
  PERFORM errorhandler.  "oWBs.Open P_Source
  CALL METHOD OF owbs 'Item' = owb
    EXPORTING #1 = 1.
  PERFORM errorhandler.  "Set oWB = oWBs.Item(1)
* Export file as PDF using the name User defined previously
  CALL METHOD OF owb 'ExportAsFixedFormat'
    EXPORTING #1 = 0       "Type = xlTypePDF
              #2 = p_dest. "FileName
  PERFORM errorhandler.  "oWB.ExportAsFixedFormat xlTypePDF, P_Dest
* Close Excel file without saving changes
  CALL METHOD OF owb 'Close'
    EXPORTING #1 = 0. "Save = False
  PERFORM errorhandler.  "oWB.Close ( Save = False)
* Tell Excel to resume updating entire worksheet with each change
  SET PROPERTY OF oexcel 'ScreenUpdating' = 1.
  PERFORM errorhandler.  "Application.ScreenUpdating = True
* Tell Excel to show worksheet to the User
  SET PROPERTY OF oexcel 'Visible' = 1.
  PERFORM errorhandler.  "oExcel.Visible = True
  CALL METHOD OF oexcel 'Quit'.
  PERFORM errorhandler.  "oExcel.Quit
* Disconnect from Excel
  FREE OBJECT oexcel.
  PERFORM errorhandler.
原文地址:https://www.cnblogs.com/Brokenshelltao/p/14976315.html