随笔 - 24,  文章 - 0,  评论 - 0,  阅读 - 11215
复制代码
 以下是 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:\Users\itstudy\Desktop\aa.docx'. 10 11 CALL METHOD OF gs_docu 'ExportAsFixedFormat' = GS_docu 12 EXPORTING 13 #1 = 'C:\Users\itstudy\Desktop\aa.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.
复制代码

 

posted on   淡淡-祥  阅读(732)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
点击右上角即可分享
微信分享提示