abap2xlsx/ZA2X/PROG/ZDEMO_EXCEL39.slnk
2015-07-13 00:00:15 +02:00

486 lines
16 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<PROG NAME="ZDEMO_EXCEL39" VARCL="X" SUBC="1" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" UCCHECK="X">
<textPool>
<language SPRAS="E">
<textElement ID="R" ENTRY="abap2xlsx Demo: Drawings" LENGTH="25 "/>
<textElement ID="S" KEY="POBJTYPE" ENTRY="D ." LENGTH="9 "/>
<textElement ID="S" KEY="P_CLASS" ENTRY="D ." LENGTH="9 "/>
<textElement ID="S" KEY="P_OBJID" ENTRY="D ." LENGTH="9 "/>
<textElement ID="S" KEY="P_PATH" ENTRY="D ." LENGTH="9 "/>
</language>
</textPool>
<source>*&amp;---------------------------------------------------------------------*
*&amp; Report ZDEMO_EXCEL16
*&amp;
*&amp;---------------------------------------------------------------------*
*&amp;
*&amp;
*&amp;---------------------------------------------------------------------*
REPORT zdemo_excel39.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_worksheet TYPE REF TO zcl_excel_worksheet,
lo_drawing TYPE REF TO zcl_excel_drawing.
DATA lv_value TYPE i.
DATA: ls_io TYPE skwf_io.
DATA: ls_upper TYPE zexcel_drawing_location,
ls_lower TYPE zexcel_drawing_location.
DATA: lo_bar1 TYPE REF TO zcl_excel_graph_bars,
lo_bar1_stacked TYPE REF TO zcl_excel_graph_bars,
lo_bar2 TYPE REF TO zcl_excel_graph_bars,
lo_pie TYPE REF TO zcl_excel_graph_pie,
lo_line TYPE REF TO zcl_excel_graph_line.
CONSTANTS: gc_save_file_name TYPE string VALUE &apos;39_Charts.xlsx&apos;.
INCLUDE zdemo_excel_outputopt_incl.
START-OF-SELECTION.
&quot; Create a pie chart and series
CREATE OBJECT lo_pie.
CALL METHOD lo_pie-&gt;create_serie
EXPORTING
ip_order = 0
ip_sheet = &apos;Values&apos;
ip_lbl_from_col = &apos;B&apos;
ip_lbl_from_row = &apos;1&apos;
ip_lbl_to_col = &apos;B&apos;
ip_lbl_to_row = &apos;3&apos;
ip_ref_from_col = &apos;A&apos;
ip_ref_from_row = &apos;1&apos;
ip_ref_to_col = &apos;A&apos;
ip_ref_to_row = &apos;3&apos;
ip_sername = &apos;My serie 1&apos;.
&quot; Set style
lo_pie-&gt;set_style( zcl_excel_graph=&gt;c_style_15 ).
&quot; Create a bar chart, series and axes
CREATE OBJECT lo_bar1.
CALL METHOD lo_bar1-&gt;create_serie
EXPORTING
ip_order = 0
ip_invertifnegative = zcl_excel_graph_bars=&gt;c_invertifnegative_no
ip_lbl = &apos;Values!$D$1:$D$3&apos;
ip_ref = &apos;Values!$C$1:$C$3&apos;
ip_sername = &apos;My serie 1&apos;.
CALL METHOD lo_bar1-&gt;create_serie
EXPORTING
ip_order = 1
ip_invertifnegative = zcl_excel_graph_bars=&gt;c_invertifnegative_no
ip_lbl = &apos;Values!$B$1:$B$3&apos;
ip_ref = &apos;Values!$A$1:$A$3&apos;
ip_sername = &apos;My serie 2&apos;.
CALL METHOD lo_bar1-&gt;create_ax
EXPORTING
* ip_axid =
ip_type = zcl_excel_graph_bars=&gt;c_catax
* ip_orientation =
* ip_delete =
* ip_axpos =
* ip_formatcode =
* ip_sourcelinked =
* ip_majortickmark =
* ip_minortickmark =
* ip_ticklblpos =
* ip_crossax =
* ip_crosses =
* ip_auto =
* ip_lblalgn =
* ip_lbloffset =
* ip_nomultilvllbl =
* ip_crossbetween =
.
CALL METHOD lo_bar1-&gt;create_ax
EXPORTING
* ip_axid =
ip_type = zcl_excel_graph_bars=&gt;c_valax
* ip_orientation =
* ip_delete =
* ip_axpos =
* ip_formatcode =
* ip_sourcelinked =
* ip_majortickmark =
* ip_minortickmark =
* ip_ticklblpos =
* ip_crossax =
* ip_crosses =
* ip_auto =
* ip_lblalgn =
* ip_lbloffset =
* ip_nomultilvllbl =
* ip_crossbetween =
.
&quot; Set style
lo_bar1-&gt;set_style( zcl_excel_graph=&gt;c_style_default ).
&quot; Set label to none
lo_bar1-&gt;set_print_lbl( zcl_excel_graph_bars=&gt;c_show_false ).
* Same barchart - but this time stacked
CREATE OBJECT lo_bar1_stacked.
CALL METHOD lo_bar1_stacked-&gt;create_serie
EXPORTING
ip_order = 0
ip_invertifnegative = zcl_excel_graph_bars=&gt;c_invertifnegative_no
ip_lbl = &apos;Values!$D$1:$D$3&apos;
ip_ref = &apos;Values!$C$1:$C$3&apos;
ip_sername = &apos;My serie 1&apos;.
CALL METHOD lo_bar1_stacked-&gt;create_serie
EXPORTING
ip_order = 1
ip_invertifnegative = zcl_excel_graph_bars=&gt;c_invertifnegative_no
ip_lbl = &apos;Values!$B$1:$B$3&apos;
ip_ref = &apos;Values!$A$1:$A$3&apos;
ip_sername = &apos;My serie 2&apos;.
CALL METHOD lo_bar1_stacked-&gt;create_ax
EXPORTING
ip_type = zcl_excel_graph_bars=&gt;c_catax .
CALL METHOD lo_bar1_stacked-&gt;create_ax
EXPORTING
ip_type = zcl_excel_graph_bars=&gt;c_valax.
&quot; Set style
lo_bar1_stacked-&gt;set_style( zcl_excel_graph=&gt;c_style_default ).
&quot; Set label to none
lo_bar1_stacked-&gt;set_print_lbl( zcl_excel_graph_bars=&gt;c_show_false ).
&quot; Make it stacked
lo_bar1_stacked-&gt;ns_groupingval = zcl_excel_graph_bars=&gt;c_groupingval_stacked.
&quot; Create a bar chart, series and axes
CREATE OBJECT lo_bar2.
CALL METHOD lo_bar2-&gt;create_serie
EXPORTING
ip_order = 0
ip_invertifnegative = zcl_excel_graph_bars=&gt;c_invertifnegative_yes
ip_lbl = &apos;Values!$D$1:$D$3&apos;
ip_ref = &apos;Values!$C$1:$C$3&apos;
ip_sername = &apos;My serie 1&apos;.
CALL METHOD lo_bar2-&gt;create_ax
EXPORTING
* ip_axid =
ip_type = zcl_excel_graph_bars=&gt;c_catax
* ip_orientation =
* ip_delete =
* ip_axpos =
* ip_formatcode =
* ip_sourcelinked =
* ip_majortickmark =
* ip_minortickmark =
* ip_ticklblpos =
* ip_crossax =
* ip_crosses =
* ip_auto =
* ip_lblalgn =
* ip_lbloffset =
* ip_nomultilvllbl =
* ip_crossbetween =
.
CALL METHOD lo_bar2-&gt;create_ax
EXPORTING
* ip_axid =
ip_type = zcl_excel_graph_bars=&gt;c_valax
* ip_orientation =
* ip_delete =
* ip_axpos =
* ip_formatcode =
* ip_sourcelinked =
* ip_majortickmark =
* ip_minortickmark =
* ip_ticklblpos =
* ip_crossax =
* ip_crosses =
* ip_auto =
* ip_lblalgn =
* ip_lbloffset =
* ip_nomultilvllbl =
* ip_crossbetween =
.
&quot; Set layout
lo_bar2-&gt;set_show_legend_key( zcl_excel_graph_bars=&gt;c_show_true ).
lo_bar2-&gt;set_show_values( zcl_excel_graph_bars=&gt;c_show_true ).
lo_bar2-&gt;set_show_cat_name( zcl_excel_graph_bars=&gt;c_show_true ).
lo_bar2-&gt;set_show_ser_name( zcl_excel_graph_bars=&gt;c_show_true ).
lo_bar2-&gt;set_show_percent( zcl_excel_graph_bars=&gt;c_show_true ).
lo_bar2-&gt;set_varycolor( zcl_excel_graph_bars=&gt;c_show_true ).
&quot; Create a line chart, series and axes
CREATE OBJECT lo_line.
CALL METHOD lo_line-&gt;create_serie
EXPORTING
ip_order = 0
ip_symbol = zcl_excel_graph_line=&gt;c_symbol_auto
ip_smooth = zcl_excel_graph_line=&gt;c_show_false
ip_lbl = &apos;Values!$D$1:$D$3&apos;
ip_ref = &apos;Values!$C$1:$C$3&apos;
ip_sername = &apos;My serie 1&apos;.
CALL METHOD lo_line-&gt;create_serie
EXPORTING
ip_order = 1
ip_symbol = zcl_excel_graph_line=&gt;c_symbol_none
ip_smooth = zcl_excel_graph_line=&gt;c_show_false
ip_lbl = &apos;Values!$B$1:$B$3&apos;
ip_ref = &apos;Values!$A$1:$A$3&apos;
ip_sername = &apos;My serie 2&apos;.
CALL METHOD lo_line-&gt;create_serie
EXPORTING
ip_order = 2
ip_symbol = zcl_excel_graph_line=&gt;c_symbol_auto
ip_smooth = zcl_excel_graph_line=&gt;c_show_false
ip_lbl = &apos;Values!$F$1:$F$3&apos;
ip_ref = &apos;Values!$E$1:$E$3&apos;
ip_sername = &apos;My serie 3&apos;.
CALL METHOD lo_line-&gt;create_ax
EXPORTING
* ip_axid =
ip_type = zcl_excel_graph_line=&gt;c_catax
* ip_orientation =
* ip_delete =
* ip_axpos =
* ip_majortickmark =
* ip_minortickmark =
* ip_ticklblpos =
* ip_crossax =
* ip_crosses =
* ip_auto =
* ip_lblalgn =
* ip_lbloffset =
* ip_nomultilvllbl =
* ip_crossbetween =
.
CALL METHOD lo_line-&gt;create_ax
EXPORTING
* ip_axid =
ip_type = zcl_excel_graph_line=&gt;c_valax
* ip_orientation =
* ip_delete =
* ip_axpos =
* ip_formatcode =
* ip_sourcelinked =
* ip_majortickmark =
* ip_minortickmark =
* ip_ticklblpos =
* ip_crossax =
* ip_crosses =
* ip_auto =
* ip_lblalgn =
* ip_lbloffset =
* ip_nomultilvllbl =
* ip_crossbetween =
.
&quot; Creates active sheet
CREATE OBJECT lo_excel.
&quot; Get active sheet (Pie sheet)
lo_worksheet = lo_excel-&gt;get_active_worksheet( ).
lo_worksheet-&gt;set_title( &apos;PieChart&apos; ).
&quot; Create global drawing, set type as pie chart, assign chart, set position and media type
lo_drawing = lo_worksheet-&gt;excel-&gt;add_new_drawing(
ip_type = zcl_excel_drawing=&gt;type_chart
ip_title = &apos;CHART PIE&apos; ).
lo_drawing-&gt;graph = lo_pie.
lo_drawing-&gt;graph_type = zcl_excel_drawing=&gt;c_graph_pie.
&quot;Set chart position (anchor 2 cells)
ls_lower-row = 30.
ls_lower-col = 20.
lo_drawing-&gt;set_position2(
EXPORTING
ip_from = ls_upper
ip_to = ls_lower ).
lo_drawing-&gt;set_media(
EXPORTING
ip_media_type = zcl_excel_drawing=&gt;c_media_type_xml ).
lo_worksheet-&gt;add_drawing( lo_drawing ).
&quot; BarChart1 sheet
lo_worksheet = lo_excel-&gt;add_new_worksheet( ).
lo_worksheet-&gt;set_title( ip_title = &apos;BarChart1&apos; ).
&quot; Create global drawing, set type as bar chart, assign chart, set position and media type
lo_drawing = lo_worksheet-&gt;excel-&gt;add_new_drawing(
ip_type = zcl_excel_drawing=&gt;type_chart
ip_title = &apos;CHART BARS WITH 2 SERIES&apos; ).
lo_drawing-&gt;graph = lo_bar1.
lo_drawing-&gt;graph_type = zcl_excel_drawing=&gt;c_graph_bars.
&quot;Set chart position (anchor 2 cells)
ls_upper-row = 0.
ls_upper-col = 11.
ls_lower-row = 22.
ls_lower-col = 21.
lo_drawing-&gt;set_position2(
EXPORTING
ip_from = ls_upper
ip_to = ls_lower ).
lo_drawing-&gt;set_media(
EXPORTING
ip_media_type = zcl_excel_drawing=&gt;c_media_type_xml ).
lo_worksheet-&gt;add_drawing( lo_drawing ).
lo_drawing = lo_worksheet-&gt;excel-&gt;add_new_drawing(
ip_type = zcl_excel_drawing=&gt;type_chart
ip_title = &apos;Stacked CHART BARS WITH 2 SER.&apos; ).
lo_drawing-&gt;graph = lo_bar1_stacked.
lo_drawing-&gt;graph_type = zcl_excel_drawing=&gt;c_graph_bars.
&quot;Set chart position (anchor 2 cells)
ls_upper-row = 0.
ls_upper-col = 1.
ls_lower-row = 22.
ls_lower-col = 10.
lo_drawing-&gt;set_position2(
EXPORTING
ip_from = ls_upper
ip_to = ls_lower ).
lo_drawing-&gt;set_media(
EXPORTING
ip_media_type = zcl_excel_drawing=&gt;c_media_type_xml ).
lo_worksheet-&gt;add_drawing( lo_drawing ).
&quot; BarChart2 sheet
lo_worksheet = lo_excel-&gt;add_new_worksheet( ).
lo_worksheet-&gt;set_title( ip_title = &apos;BarChart2&apos; ).
&quot; Create global drawing, set type as bar chart, assign chart, set position and media type
lo_drawing = lo_worksheet-&gt;excel-&gt;add_new_drawing(
ip_type = zcl_excel_drawing=&gt;type_chart
ip_title = &apos;CHART BARS WITH 1 SERIE&apos; ).
lo_drawing-&gt;graph = lo_bar2.
lo_drawing-&gt;graph_type = zcl_excel_drawing=&gt;c_graph_bars.
&quot;Set chart position (anchor 2 cells)
ls_upper-row = 0.
ls_upper-col = 0.
ls_lower-row = 30.
ls_lower-col = 20.
lo_drawing-&gt;set_position2(
EXPORTING
ip_from = ls_upper
ip_to = ls_lower ).
lo_drawing-&gt;set_media(
EXPORTING
ip_media_type = zcl_excel_drawing=&gt;c_media_type_xml ).
lo_worksheet-&gt;add_drawing( lo_drawing ).
&quot; LineChart sheet
lo_worksheet = lo_excel-&gt;add_new_worksheet( ).
lo_worksheet-&gt;set_title( ip_title = &apos;LineChart&apos; ).
&quot; Create global drawing, set type as line chart, assign chart, set position and media type
lo_drawing = lo_worksheet-&gt;excel-&gt;add_new_drawing(
ip_type = zcl_excel_drawing=&gt;type_chart
ip_title = &apos;CHART LINES&apos; ).
lo_drawing-&gt;graph = lo_line.
lo_drawing-&gt;graph_type = zcl_excel_drawing=&gt;c_graph_line.
&quot;Set chart position (anchor 2 cells)
ls_upper-row = 0.
ls_upper-col = 0.
ls_lower-row = 30.
ls_lower-col = 20.
lo_drawing-&gt;set_position2(
EXPORTING
ip_from = ls_upper
ip_to = ls_lower ).
lo_drawing-&gt;set_media(
EXPORTING
ip_media_type = zcl_excel_drawing=&gt;c_media_type_xml ).
lo_worksheet-&gt;add_drawing( lo_drawing ).
&quot; Values sheet
lo_worksheet = lo_excel-&gt;add_new_worksheet( ).
lo_worksheet-&gt;set_title( ip_title = &apos;Values&apos; ).
&quot; Set values for chart
lv_value = 1.
lo_worksheet-&gt;set_cell( ip_column = &apos;A&apos; ip_row = 1 ip_value = lv_value ).
lv_value = 2.
lo_worksheet-&gt;set_cell( ip_column = &apos;A&apos; ip_row = 2 ip_value = lv_value ).
lv_value = 3.
lo_worksheet-&gt;set_cell( ip_column = &apos;A&apos; ip_row = 3 ip_value = lv_value ).
&quot; Set labels for chart
lo_worksheet-&gt;set_cell( ip_column = &apos;B&apos; ip_row = 1 ip_value = &apos;One&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;B&apos; ip_row = 2 ip_value = &apos;Two&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;B&apos; ip_row = 3 ip_value = &apos;Three&apos; ).
&quot; Set values for chart
lv_value = 3.
lo_worksheet-&gt;set_cell( ip_column = &apos;C&apos; ip_row = 1 ip_value = lv_value ).
lv_value = 2.
lo_worksheet-&gt;set_cell( ip_column = &apos;C&apos; ip_row = 2 ip_value = lv_value ).
lv_value = -1.
lo_worksheet-&gt;set_cell( ip_column = &apos;C&apos; ip_row = 3 ip_value = lv_value ).
&quot; Set labels for chart
lo_worksheet-&gt;set_cell( ip_column = &apos;D&apos; ip_row = 3 ip_value = &apos;One (Minus)&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;D&apos; ip_row = 2 ip_value = &apos;Two&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;D&apos; ip_row = 1 ip_value = &apos;Three&apos; ).
&quot; Set values for chart
lv_value = 3.
lo_worksheet-&gt;set_cell( ip_column = &apos;E&apos; ip_row = 1 ip_value = lv_value ).
lv_value = 1.
lo_worksheet-&gt;set_cell( ip_column = &apos;E&apos; ip_row = 2 ip_value = lv_value ).
lv_value = 2.
lo_worksheet-&gt;set_cell( ip_column = &apos;E&apos; ip_row = 3 ip_value = lv_value ).
&quot; Set labels for chart
lo_worksheet-&gt;set_cell( ip_column = &apos;F&apos; ip_row = 3 ip_value = &apos;Two&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;F&apos; ip_row = 2 ip_value = &apos;One&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;F&apos; ip_row = 1 ip_value = &apos;Three&apos; ).
*** Create output
lcl_output=&gt;output( lo_excel ).</source>
</PROG>