abap2xlsx / abap2xlsx

Generate your professional Excel spreadsheet from ABAP
https://abap2xlsx.github.io/abap2xlsx/
Apache License 2.0
720 stars 291 forks source link

No cell color with bind_alv #1282

Open AlexandreHT opened 2 weeks ago

AlexandreHT commented 2 weeks ago

Hi, When I use bind_alv with an SALV that has colored cells, the Excel file produced by ABAP2xlsx does not have any colors (Option 1 in the demo program). Surprisingly, if I use the code contained in bin_alv (Option 2), it works.

Steps to reproduce:

  1. Execute demo program with option Direct display => SALV displayed in SAP with colored cells
  2. Execute with option Save to frontend => Excel file doesn't have colored cells
  3. Change program: Comment Option 1 and uncomment Option 2 / Activate
  4. Execute with option Save to frontend => Excel file has colored cells
report zdemo_excel_issue.

types: begin of ty_t005t_line,
         mandt   type mandt,
         spras   type spras,
         land1   type land1,
         landx   type landx,
         natio   type natio,
         landx50 type landx50,
         natio50 type natio50,
         colors  type lvc_t_scol,
       end of ty_t005t_line,
       ty_t005t_lines type table of ty_t005t_line.

data lt_test type ty_t005t_lines.

constants: gc_save_file_name type string value 'issue.xlsx'.
include zdemo_excel_outputopt_incl.

start-of-selection.
  perform load_fixed_data changing lt_test.

  try.
      cl_salv_table=>factory(
        importing
          r_salv_table = data(salv_table)
        changing
          t_table      = lt_test ).

      data(columns) = salv_table->get_columns( ).
      columns->set_color_column( 'COLORS' ).

      if rb_show = 'X'.
        salv_table->display( ).
      else.
        data(excel)          = new zcl_excel( ).
        data(worksheet) = excel->get_active_worksheet( ).

**** Option 1 : no colors in output ****
        worksheet->bind_alv(
            io_alv      = salv_table
            it_table    = lt_test ).

**** Option 2 : colors in output ****
*        data(lo_converter) = new zcl_excel_converter( ).
*        lo_converter->convert(
*          exporting
*            io_alv         = salv_table
*            it_table       = lt_test
**            i_row_int      = i_top
**            i_column_int   = i_left
**            i_table        = i_table
**            i_style_table  = table_style
*            io_worksheet   = worksheet
*          changing
*            co_excel       = excel ).

*** Create output
        lcl_output=>output( excel ).
      endif.

    catch cx_salv_error into data(exception).
      message exception type 'E'.
  endtry.

form load_fixed_data changing ct_test type ty_t005t_lines.
  data: lt_lines  type table of string,
        lv_line   type string,
        lt_fields type table of string,
        lv_comp   type i,
        lv_field  type string,
        ls_test   type ty_t005t_line.
*        ls_test   type t005t.
  field-symbols: <lv_field> type simple.

  append '001 E AD Andorra    Andorran    Andorra    Andorran   ' to lt_lines.
  append '001 E BE Belgium    Belgian     Belgium    Belgian    ' to lt_lines.
  append '001 E DE Germany    German      Germany    German     ' to lt_lines.
  append '001 E FM Micronesia Micronesian Micronesia Micronesian' to lt_lines.
  loop at lt_lines into lv_line.
    clear ls_test.

    condense lv_line.
    split lv_line at space into table lt_fields.
    lv_comp = 1.
    loop at lt_fields into lv_field.
      assign component lv_comp of structure ls_test to <lv_field>.
      <lv_field> = lv_field.
      lv_comp = lv_comp + 1.
    endloop.

    data(div) = conv f( sy-tabix / 2 ).

    if frac( div ) = 0.
      insert value lvc_s_scol( fname = 'LAND1' color = value #( col = 5 int = '1' inv = '0' ) ) into table ls_test-colors.
    endif.

    append ls_test to ct_test.
  endloop.
endform.
darnoc312 commented 2 weeks ago

And if you like more bugs like this try the following (of course using convert):

    IF frac( div ) = 0.
      INSERT VALUE lvc_s_scol( fname = 'LAND1' color = VALUE #( col = 5 int = '1' inv = '0' ) ) INTO TABLE ls_test-colors.
      INSERT VALUE lvc_s_scol( fname = space color = VALUE #( col = 1 int = '1' inv = '0' ) ) INTO TABLE ls_test-colors.
    ENDIF.

SALV Output looks good, but in ABAP2XLSX the line color wins even in the LAND1 column.

AlexandreHT commented 2 weeks ago

Yes but it's a different bug. Here the point is that I have the bug when I call bind_alv (Option 1) but I have the expected result when I call the converter, (Option 2). Which is surprising considering that bind_alv mainly call the converter.

  METHOD bind_alv.
    DATA: lo_converter TYPE REF TO zcl_excel_converter.

    CREATE OBJECT lo_converter.

    TRY.
        lo_converter->convert(
          EXPORTING
            io_alv         = io_alv
            it_table       = it_table
            i_row_int      = i_top
            i_column_int   = i_left
            i_table        = i_table
            i_style_table  = table_style
            io_worksheet   = me
          CHANGING
            co_excel       = excel ).
      CATCH zcx_excel .
    ENDTRY.

  ENDMETHOD.