abap2xlsx/ZA2X/PROG/ZDEMO_EXCEL10.slnk
Alessandro Iannacci 1288a1a272 Issue #383 - Report 10 modified to show the new functionality
Issue #383 - Report 10 modified to show the new functionality
2015-06-23 15:02:47 +02:00

105 lines
4.8 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<PROG NAME="ZDEMO_EXCEL10" VARCL="X" SUBC="1" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" UCCHECK="X">
<textPool>
<language SPRAS="E">
<textElement ID="R" ENTRY="abap2xlsx Demo: Format internal table with field catalog" LENGTH="57 "/>
<textElement ID="S" KEY="P_PATH" ENTRY="D ." LENGTH="9 "/>
</language>
</textPool>
<source>*&amp;---------------------------------------------------------------------*
*&amp; Report ZDEMO_EXCEL10
*&amp;
*&amp;---------------------------------------------------------------------*
*&amp;
*&amp;
*&amp;---------------------------------------------------------------------*
REPORT zdemo_excel10.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_worksheet TYPE REF TO zcl_excel_worksheet,
lo_style_conditional2 TYPE REF TO zcl_excel_style_conditional,
column_dimension TYPE REF TO zcl_excel_worksheet_columndime.
DATA: lt_field_catalog TYPE zexcel_t_fieldcatalog,
ls_table_settings TYPE zexcel_s_table_settings,
ls_iconset TYPE zexcel_conditional_iconset.
CONSTANTS: gc_save_file_name TYPE string VALUE &apos;10_iTabFieldCatalog.xlsx&apos;.
INCLUDE zdemo_excel_outputopt_incl.
START-OF-SELECTION.
FIELD-SYMBOLS: &lt;fs_field_catalog&gt; TYPE zexcel_s_fieldcatalog.
&quot; Creates active sheet
CREATE OBJECT lo_excel.
&quot; Get active sheet
lo_worksheet = lo_excel-&gt;get_active_worksheet( ).
lo_worksheet-&gt;set_title( &apos;Internal table&apos; ).
ls_iconset-iconset = zcl_excel_style_conditional=&gt;c_iconset_5arrows.
ls_iconset-cfvo1_type = zcl_excel_style_conditional=&gt;c_cfvo_type_percent.
ls_iconset-cfvo1_value = &apos;0&apos;.
ls_iconset-cfvo2_type = zcl_excel_style_conditional=&gt;c_cfvo_type_percent.
ls_iconset-cfvo2_value = &apos;20&apos;.
ls_iconset-cfvo3_type = zcl_excel_style_conditional=&gt;c_cfvo_type_percent.
ls_iconset-cfvo3_value = &apos;40&apos;.
ls_iconset-cfvo4_type = zcl_excel_style_conditional=&gt;c_cfvo_type_percent.
ls_iconset-cfvo4_value = &apos;60&apos;.
ls_iconset-cfvo5_type = zcl_excel_style_conditional=&gt;c_cfvo_type_percent.
ls_iconset-cfvo5_value = &apos;80&apos;.
ls_iconset-showvalue = zcl_excel_style_conditional=&gt;c_showvalue_true.
&quot;Conditional style
lo_style_conditional2 = lo_worksheet-&gt;add_new_conditional_style( ).
lo_style_conditional2-&gt;rule = zcl_excel_style_conditional=&gt;c_rule_iconset.
lo_style_conditional2-&gt;mode_iconset = ls_iconset.
lo_style_conditional2-&gt;priority = 1.
DATA lt_test TYPE TABLE OF sflight.
SELECT * FROM sflight INTO TABLE lt_test. &quot;#EC CI_NOWHERE
lt_field_catalog = zcl_excel_common=&gt;get_fieldcatalog( ip_table = lt_test ).
LOOP AT lt_field_catalog ASSIGNING &lt;fs_field_catalog&gt;.
CASE &lt;fs_field_catalog&gt;-fieldname.
WHEN &apos;CARRID&apos;.
&lt;fs_field_catalog&gt;-position = 3.
&lt;fs_field_catalog&gt;-dynpfld = abap_true.
&lt;fs_field_catalog&gt;-totals_function = zcl_excel_table=&gt;totals_function_count.
WHEN &apos;CONNID&apos;.
&lt;fs_field_catalog&gt;-position = 4.
&lt;fs_field_catalog&gt;-dynpfld = abap_true.
&lt;fs_field_catalog&gt;-abap_type = cl_abap_typedescr=&gt;typekind_int.
&quot;This avoid the excel warning that the number is formatted as a text: abap2xlsx is not able to recognize numc as a number so it formats the number as a text with
&quot;the related warning. You can force the type and the framework will correctly format the number as a number
WHEN &apos;FLDATE&apos;.
&lt;fs_field_catalog&gt;-position = 2.
&lt;fs_field_catalog&gt;-dynpfld = abap_true.
WHEN &apos;PRICE&apos;.
&lt;fs_field_catalog&gt;-position = 1.
&lt;fs_field_catalog&gt;-dynpfld = abap_true.
&lt;fs_field_catalog&gt;-totals_function = zcl_excel_table=&gt;totals_function_sum.
&lt;fs_field_catalog&gt;-cond_style = lo_style_conditional2.
WHEN OTHERS.
&lt;fs_field_catalog&gt;-dynpfld = abap_false.
ENDCASE.
ENDLOOP.
ls_table_settings-table_style = zcl_excel_table=&gt;builtinstyle_medium5.
lo_worksheet-&gt;bind_table( ip_table = lt_test
is_table_settings = ls_table_settings
it_field_catalog = lt_field_catalog ).
column_dimension = lo_worksheet-&gt;get_column_dimension( ip_column = &apos;D&apos; ). &quot;make date field a bit wider
column_dimension-&gt;set_width( ip_width = 13 ).
*** Create output
lcl_output=&gt;output( lo_excel ).</source>
</PROG>