14.01.2020 Views

ABAP_to_the_Future

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Enhancing Custom Reports with ABAP2XLSX 11.2

CONSTANTS: lc_strength_column

TYPE zexcel_cell_column_alpha VALUE 'E'.

Listing 11.13 Strength Column

Next, set up the three colors needed in this example; as you will see in Listing

11.14, this is quite compli cated, which is often the case when you have a large

amount of flexibility. The flexibility here is that although there are constants for

common colors such as green via the ei ght-digit hexadecimal codes that Excel

uses for colors, you can have any color under the sun. The ZDEMO_EXCEL21 program,

which comes with ABAP2XLSX, demonstrates all the colors available to

you. Each color will be represented by a GUID, which, as you’ve seen throughout

this book, is a very long string that is only understandable by a computer.

For each color, set up a style object, indicate that there will be a solid background,

and specify what color that background will be. Then, call the GET_GUID

method of the style object to turn the human-friendly instructions into something

a computer can work with. You will note that the colors are set up to be

used based on the Excel object as opposed to the worksheet object, as they can be

used in any worksheet.

DATA:

lo_style_conditional TYPE REF TO zcl_excel_style_conditional,

lo_style_1

TYPE REF TO zcl_excel_style,

lo_style_2

TYPE REF TO zcl_excel_style,

lo_style_3

TYPE REF TO zcl_excel_style,

ld_green_guid TYPE zexcel_cell_style,

ld_red_guid

TYPE zexcel_cell_style,

ld_yellow_guid TYPE zexcel_cell_style,

ls_cellis

TYPE zexcel_conditional_cellis.

lo_style_1 = lo_excel->add_new_style( ).

lo_style_1->fill->filltype = zcl_excel_style_fill=>c_fill_solid.

lo_style_1->fill->bgcolor-rgb = zcl_excel_style_color=>c_green.

ld_green_guid = lo_style_1->get_guid( ).

lo_style_2 = lo_excel->add_new_style( ).

lo_style_2->fill->filltype = zcl_excel_style_fill=>c_fill_solid.

lo_style_2->fill->bgcolor-rgb = 'FFFF99FF'. "Soft Red Pink Really

ld_red_guid = lo_style_2->get_guid( ).

lo_style_3 = lo_excel->add_new_style( ).

lo_style_3->fill->filltype = zcl_excel_style_fill=>c_fill_solid.

lo_style_3->fill->bgcolor-rgb = 'FFFF9900'. "Orange

ld_yellow_guid = lo_style_3->get_guid( ).

Listing 11.14 Creating Colors to Use in a Spreadsheet

475

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!