Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor method change_cell_style in zcl_excel_worksheet #904

Merged
merged 4 commits into from Dec 14, 2021

Conversation

sandraros
Copy link
Collaborator

@sandraros sandraros commented Dec 7, 2021

Creation of new class zcl_excel_style_changer and refactor of change_cell_style to use it. There's no fix, no feature change, it helps to go towards #524.

Future plan: with this new class, it will be easy to create a new method change_area_style so that to change the style of many cells at a time. That would permit to rewrite zdemo_excel40, for the exact same result, instead of calling set_cell and change_cell_style repeatedly for each cell in 100 rows * 20 columns, the methods set_area and change_area_style could be called once:

    lo_worksheet->set_area(
          ip_column_start = 1
          ip_column_end   = 20
          ip_row          = 1
          ip_row_to       = 100
          ip_formula      = 'CHAR(64+COLUMN())&TEXT(ROW(),"       ?0")' ).

    lo_changer = zcl_excel_style_changer=>create( lo_excel ).
    lo_changer->set_fill_filltype( zcl_excel_style_fill=>c_fill_solid ).
    lo_changer->set_fill_fgcolor_rgb( zcl_excel_style_color=>c_yellow ).
    lo_worksheet->change_area_style(
          ip_column_start = 1
          ip_column_end   = 20
          ip_row          = 1
          ip_row_to       = 3
          ip_changer      = lo_changer ).

    lo_changer = zcl_excel_style_changer=>create( lo_excel ).
    lo_changer->set_font_color_rgb( zcl_excel_style_color=>c_red ).
    lo_worksheet->change_area_style(
          ip_column_start = 1
          ip_column_end   = 4
          ip_row          = 1
          ip_row_to       = 100
          ip_changer      = lo_changer ).

@sandraros sandraros marked this pull request as ready for review December 7, 2021 21:25
Copy link
Member

@AndreaBorgia-Abo AndreaBorgia-Abo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a regression with an export parameter and a couple of commented-out methods I cannot understand.

src/zcl_excel_style_changer.clas.abap Outdated Show resolved Hide resolved
src/zcl_excel_worksheet.clas.abap Show resolved Hide resolved
src/zcl_excel_style_changer.clas.abap Outdated Show resolved Hide resolved
@sandraros
Copy link
Collaborator Author

Program for testing the ep_guid parameter returned by change_cell_style:

REPORT.
DATA: lo_excel     TYPE REF TO zcl_excel,
      lo_worksheet TYPE REF TO zcl_excel_worksheet.
CONSTANTS: gc_save_file_name TYPE string VALUE 'PR_904.xlsx'.
INCLUDE zdemo_excel_outputopt_incl.
START-OF-SELECTION.
  CREATE OBJECT lo_excel.
  lo_worksheet = lo_excel->get_active_worksheet( ).
  lo_worksheet->set_cell( ip_column = 1 ip_row = 1 ip_value = 'A1' ).
  lo_worksheet->set_cell( ip_column = 2 ip_row = 1 ip_value = 'B1' ).
  lo_worksheet->set_cell( ip_column = 3 ip_row = 1 ip_value = 'C1' ).
  DATA(lv_guid) = lo_worksheet->change_cell_style(
      ip_column           = 1
      ip_row              = 1
      ip_fill_filltype    = zcl_excel_style_fill=>c_fill_solid
      ip_fill_fgcolor_rgb = zcl_excel_style_color=>c_yellow ).
  lo_worksheet->set_cell_style( ip_column = 2 ip_row = 1 ip_style = lv_guid ).
  DATA(lv_guid2) = lo_worksheet->change_cell_style(
      ip_column         = 1
      ip_row            = 1
      ip_font_color_rgb = zcl_excel_style_color=>c_red ).
  lo_worksheet->set_cell_style( ip_column = 3 ip_row = 1 ip_style = lv_guid2 ).
  lcl_output=>output( lo_excel ).

Copy link
Member

@AndreaBorgia-Abo AndreaBorgia-Abo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AndreaBorgia-Abo AndreaBorgia-Abo merged commit 0f51d6d into master Dec 14, 2021
@AndreaBorgia-Abo AndreaBorgia-Abo deleted the sandraros/refactor-change-cell-style branch December 14, 2021 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants