SAP ABAP2XLSX输出一个复杂的EXCEL表之ZDEMO_EXCEL2

1.ABAP2XLSX手动创建一个Excel表并输出,参考标准演示文档ZDEMO_EXCEL2

  • 代码:

    DATA: lo_excel                TYPE REF TO zcl_excel,
          lo_worksheet            TYPE REF TO zcl_excel_worksheet,
          lo_style_bold           TYPE REF TO zcl_excel_style,
          lo_style_underline      TYPE REF TO zcl_excel_style,
          lo_style_filled         TYPE REF TO zcl_excel_style,
          lo_style_border         TYPE REF TO zcl_excel_style,
          lo_style_button         TYPE REF TO zcl_excel_style,
          lo_border_dark          TYPE REF TO zcl_excel_style_border,
          lo_border_light         TYPE REF TO zcl_excel_style_border.
    
    DATA: lv_style_bold_guid         TYPE zexcel_cell_style,
          lv_style_underline_guid    TYPE zexcel_cell_style,
          lv_style_filled_guid       TYPE zexcel_cell_style,
          lv_style_filled_green_guid TYPE zexcel_cell_style,
          lv_style_border_guid       TYPE zexcel_cell_style,
          lv_style_button_guid       TYPE zexcel_cell_style,
          lv_style_filled_turquoise_guid TYPE zexcel_cell_style,
          lv_style_gr_cornerlb_guid TYPE zexcel_cell_style,
          lv_style_gr_cornerlt_guid TYPE zexcel_cell_style,
          lv_style_gr_cornerrb_guid TYPE zexcel_cell_style,
          lv_style_gr_cornerrt_guid TYPE zexcel_cell_style,
          lv_style_gr_horizontal90_guid TYPE zexcel_cell_style,
          lv_style_gr_horizontal270_guid TYPE zexcel_cell_style,
          lv_style_gr_horizontalb_guid TYPE zexcel_cell_style,
          lv_style_gr_vertical_guid TYPE zexcel_cell_style,
          lv_style_gr_vertical2_guid TYPE zexcel_cell_style,
          lv_style_gr_fromcenter_guid TYPE zexcel_cell_style,
          lv_style_gr_diagonal45_guid TYPE zexcel_cell_style,
          lv_style_gr_diagonal45b_guid TYPE zexcel_cell_style,
          lv_style_gr_diagonal135_guid TYPE zexcel_cell_style,
          lv_style_gr_diagonal135b_guid TYPE zexcel_cell_style     .
    
    DATA: lv_file                 TYPE xstring,
          lv_bytecount            TYPE i,
          lt_file_tab             TYPE solix_tab.
    
    DATA: lv_full_path      TYPE string,
          lv_workdir        TYPE string,
          lv_file_separator TYPE c.
    DATA: lo_row_dim TYPE REF TO zcl_excel_worksheet_rowdimensi,
          column_dimension TYPE REF TO zcl_excel_worksheet_columndime.
    
    CONSTANTS: gc_save_file_name TYPE string VALUE 'zdemo_excel2'.
    INCLUDE zdemo_excel_outputopt_incl.
    
    
    
    START-OF-SELECTION.
    
      CREATE OBJECT lo_excel.
    
      " Create border object
      CREATE OBJECT lo_border_dark.         "设置单元格黑色边框
      lo_border_dark->border_color-rgb = zcl_excel_style_color=>c_black.
      lo_border_dark->border_style = zcl_excel_style_border=>c_border_thin.
    
      CREATE OBJECT lo_border_light.        "设置单元格灰色边框
      lo_border_light->border_color-rgb = zcl_excel_style_color=>c_gray.
      lo_border_light->border_style = zcl_excel_style_border=>c_border_thin.
    
      " Create a bold / italic style
      lo_style_bold               = lo_excel->add_new_style( ).         "Skip一行,针对样式表,并不是输出Excel跳行
      lo_style_bold->font->bold   = abap_true.      "设置字体加粗
      lo_style_bold->font->italic = abap_true.      "设置斜字体
      lo_style_bold->font->name   = zcl_excel_style_font=>c_name_arial. "设置显示字体为 Arial
      lo_style_bold->font->scheme = zcl_excel_style_font=>c_scheme_none.  "设置字体主题
      lo_style_bold->font->color-rgb  = zcl_excel_style_color=>c_red.     "设置字体颜色为红色
      lv_style_bold_guid          = lo_style_bold->get_guid( ).           "给此样式分配一个GUID
    
    
      " Create an underline double style
      lo_style_underline                        = lo_excel->add_new_style( ).
      lo_style_underline->font->underline       = abap_true.              "增加下划线
      lo_style_underline->font->underline_mode  = zcl_excel_style_font=>c_underline_double.   "设置下划线2行
      lo_style_underline->font->name            = zcl_excel_style_font=>c_name_roman.
      lo_style_underline->font->scheme          = zcl_excel_style_font=>c_scheme_none.
      lo_style_underline->font->family          = zcl_excel_style_font=>c_family_roman. "Font Family 把多个字体名称作为一个“回退”系统来保存。如果浏览器不支持第一个字体,则会尝试下一个
      lv_style_underline_guid                   = lo_style_underline->get_guid( ).
    
      " Create filled style
      lo_style_filled                 = lo_excel->add_new_style( ).
      lo_style_filled->fill->filltype = zcl_excel_style_fill=>C_FILL_PATTERN_GRAY0625."设置单元格背景图案样式
      lo_style_filled->fill->fgcolor-theme  = zcl_excel_style_color=>c_theme_accent6.     "设置字体颜色主题
      lv_style_filled_guid            = lo_style_filled->get_guid( ).
    
      " Create border with button effects
      lo_style_button                   = lo_excel->add_new_style( ).
      lo_style_button->borders->right   = lo_border_dark.	  "设置右边框黑色
      lo_style_button->borders->down    = lo_border_dark.   "设置下边框黑色
      lo_style_button->borders->left    = lo_border_light.  "设置左边框灰色
      lo_style_button->borders->top     = lo_border_light.  "设置上边框灰色
      lv_style_button_guid              = lo_style_button->get_guid( ).
    
    
      "Create style with border
      lo_style_border                         = lo_excel->add_new_style( ).
      lo_style_border->borders->allborders    = lo_border_dark.           "设置单元格所有边框为lo_border_dark 黑色
      lo_style_border->borders->diagonal      = lo_border_dark.         "设置单元格对角线
      lo_style_border->borders->diagonal_mode = zcl_excel_style_borders=>c_diagonal_both.     "设置的那远哥对角线样式 C_DIAGONAL_DOWN
      lv_style_border_guid                    = lo_style_border->get_guid( ).
    
    
      " Create filled style green
      lo_style_filled                     = lo_excel->add_new_style( ).
      lo_style_filled->fill->filltype     = zcl_excel_style_fill=>c_fill_solid.
      lo_style_filled->fill->fgcolor-rgb  = zcl_excel_style_color=>c_green.
      lo_style_filled->font->name         = zcl_excel_style_font=>c_name_cambria.
      lo_style_filled->font->scheme       = zcl_excel_style_font=>c_scheme_major.
      lv_style_filled_green_guid          = lo_style_filled->get_guid( ).
    
    
    
      " Create filled with gradients    "设置渐变样式,B10-b23 C10-C23背景渐变样式
      lo_style_filled                     = lo_excel->add_new_style( ).
      lo_style_filled->fill->filltype     = zcl_excel_style_fill=>c_fill_gradient_cornerlb.
      lo_style_filled->fill->fgcolor-rgb  = zcl_excel_style_color=>c_blue.
      lo_style_filled->fill->bgcolor-rgb  = zcl_excel_style_color=>c_white.
    
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值