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.

相关推荐
又蓝7 小时前
使用 Python 操作 Excel 表格
开发语言·python·excel
m0_7482309411 小时前
Rust赋能前端: 纯血前端将 Table 导出 Excel
前端·rust·excel
Swift社区12 小时前
Excel 列名称转换问题 Swift 解答
开发语言·excel·swift
neeef_se13 小时前
Vue中使用a标签下载静态资源文件(比如excel、pdf等),纯前端操作
前端·vue.js·excel
℘团子এ13 小时前
js和html中,将Excel文件渲染在页面上
javascript·html·excel
菠萝蚊鸭1 天前
Dhatim FastExcel 读写 Excel 文件
java·excel·fastexcel
一只小灿灿1 天前
VB.NET在 Excel 二次开发中的全面应用
.net·excel
是小崔啊1 天前
开源轮子 - EasyExcel01(核心api)
java·开发语言·开源·excel·阿里巴巴
Excel_easy1 天前
批量识别工作表中二维码信息-Excel易用宝
excel·wps
m0_748255261 天前
easyExcel导出大数据量EXCEL文件,前端实现进度条或者遮罩层
前端·excel