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_exist
    EXPORTING
      file                 = output_path_pdf
    RECEIVING
      result               = DATA(l_res)
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      wrong_parameter      = 3
      not_supported_by_gui = 4
      OTHERS               = 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_delete
    EXPORTING
      filename             = output_path_xlsx
    CHANGING
      rc                   = l_dummy_rc
    EXCEPTIONS
      file_delete_failed   = 1
      cntl_error           = 2
      error_no_gui         = 3
      file_not_found       = 4
      access_denied        = 5
      unknown_error        = 6
      not_supported_by_gui = 7
      wrong_parameter      = 8
      OTHERS               = 9.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDIF.

ENDMETHOD.

相关推荐
乘风!4 小时前
Java导出excel,表格插入pdf附件,以及实现过程中遇见的坑
java·pdf·excel
程序猿熊跃晖12 小时前
Excel 数据导入与 SQL 生成:基于 Hutool 和 Apache POI 的优雅实践
sql·apache·excel
IT技术分享社区13 小时前
解锁Excel超能力:方方格子插件介绍
excel·电脑技巧
CodeCraft Studio2 天前
Excel处理控件Spire.XLS系列教程:C# 合并、或取消合并 Excel 单元格
前端·c#·excel
云心雨禅2 天前
Vim操作指令全解析
编辑器·vim·excel
安分小尧2 天前
[特殊字符] 使用 Handsontable 构建一个支持 Excel 公式计算的动态表格
前端·javascript·react.js·typescript·excel
hello_simon2 天前
在线小白工具,PPT转PDF支持多种热门工具,支持批量转换,操作简单,高效适合各种需求
pdf·html·powerpoint·excel·pdf转html·excel转pdf格式
Tttian6222 天前
Python办公自动化(3)对Excel的操作
开发语言·python·excel
有趣的我2 天前
vim的操作
编辑器·vim·excel
woniu_maggie2 天前
SAP EXCEL DOI 详解
开发语言·后端·excel