abap2xlsx/ZA2X/PROG/ZDEMO_EXCEL21.slnk
Ivan 24c5fca308 Update slinkees
Update of all the slinkees files with the latest version of SAPLink to
simplify merge of pull request
2015-01-12 14:55:28 -06:00

133 lines
4.3 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<PROG NAME="ZDEMO_EXCEL21" VARCL="X" SUBC="1" RSTAT="T" RMAND="000" RLOAD="E" FIXPT="X" UCCHECK="X">
<textPool>
<language SPRAS="E">
<textElement ID="R" LENGTH="38 "/>
<textElement ID="S" KEY="P_PATH" ENTRY="D ." LENGTH="9 "/>
</language>
</textPool>
<source>*&amp;---------------------------------------------------------------------*
*&amp; Report ZDEMO_EXCEL21
*&amp;
*&amp;---------------------------------------------------------------------*
*&amp;
*&amp;
*&amp;---------------------------------------------------------------------*
REPORT zdemo_excel21.
TYPES:
BEGIN OF t_color_style,
color TYPE zexcel_style_color_argb,
style TYPE zexcel_cell_style,
END OF t_color_style.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_worksheet TYPE REF TO zcl_excel_worksheet,
lo_style_filled TYPE REF TO zcl_excel_style.
DATA: color_styles TYPE TABLE OF t_color_style.
FIELD-SYMBOLS: &lt;color_style&gt; LIKE LINE OF color_styles.
CONSTANTS: max TYPE i VALUE 255,
step TYPE i VALUE 51.
DATA: red TYPE i,
green TYPE i,
blue TYPE i,
red_hex(1) TYPE x,
green_hex(1) TYPE x,
blue_hex(1) TYPE x,
red_str TYPE string,
green_str TYPE string,
blue_str TYPE string.
DATA: color TYPE zexcel_style_color_argb,
tint TYPE zexcel_style_color_tint.
DATA: row TYPE i,
row_tmp TYPE i,
column TYPE zexcel_cell_column VALUE 1,
col_str TYPE zexcel_cell_column_alpha.
CONSTANTS: gc_save_file_name TYPE string VALUE &apos;21_BackgroundColorPicker.xlsx&apos;.
INCLUDE zdemo_excel_outputopt_incl.
START-OF-SELECTION.
&quot; Creates active sheet
CREATE OBJECT lo_excel.
WHILE red &lt;= max.
green = 0.
WHILE green &lt;= max.
blue = 0.
WHILE blue &lt;= max.
red_hex = red.
red_str = red_hex.
green_hex = green.
green_str = green_hex.
blue_hex = blue.
blue_str = blue_hex.
&quot; Create filled
CONCATENATE &apos;FF&apos; red_str green_str blue_str INTO color.
APPEND INITIAL LINE TO color_styles ASSIGNING &lt;color_style&gt;.
lo_style_filled = lo_excel-&gt;add_new_style( ).
lo_style_filled-&gt;fill-&gt;filltype = zcl_excel_style_fill=&gt;c_fill_solid.
lo_style_filled-&gt;fill-&gt;fgcolor-rgb = color.
&lt;color_style&gt;-color = color.
&lt;color_style&gt;-style = lo_style_filled-&gt;get_guid( ).
blue = blue + step.
ENDWHILE.
green = green + step.
ENDWHILE.
red = red + step.
ENDWHILE.
&quot; Get active sheet
lo_worksheet = lo_excel-&gt;get_active_worksheet( ).
lo_worksheet-&gt;set_title( &apos;Color Picker&apos; ).
LOOP AT color_styles ASSIGNING &lt;color_style&gt;.
row_tmp = ( max / step + 1 ) * 3.
IF row = row_tmp.
row = 0.
column = column + 1.
ENDIF.
row = row + 1.
col_str = zcl_excel_common=&gt;convert_column2alpha( column ).
&quot; Fill the cell and apply one style
lo_worksheet-&gt;set_cell( ip_column = col_str
ip_row = row
ip_value = &lt;color_style&gt;-color
ip_style = &lt;color_style&gt;-style ).
ENDLOOP.
row = row + 2.
tint = &apos;-0.5&apos;.
DO 10 TIMES.
column = 1.
DO 10 TIMES.
lo_style_filled = lo_excel-&gt;add_new_style( ).
lo_style_filled-&gt;fill-&gt;filltype = zcl_excel_style_fill=&gt;c_fill_solid.
lo_style_filled-&gt;fill-&gt;fgcolor-theme = sy-index - 1.
lo_style_filled-&gt;fill-&gt;fgcolor-tint = tint.
&lt;color_style&gt;-style = lo_style_filled-&gt;get_guid( ).
col_str = zcl_excel_common=&gt;convert_column2alpha( column ).
lo_worksheet-&gt;set_cell_style( ip_column = col_str
ip_row = row
ip_style = &lt;color_style&gt;-style ).
ADD 1 TO column.
ENDDO.
ADD &apos;0.1&apos; TO tint.
ADD 1 TO row.
ENDDO.
*** Create output
lcl_output=&gt;output( lo_excel ).</source>
</PROG>