abap2xlsx/ZA2X/PROG/ZDEMO_EXCEL14.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

170 lines
8.5 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8"?>
<PROG NAME="ZDEMO_EXCEL14" VARCL="X" SUBC="1" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" UCCHECK="X">
<textPool>
<language SPRAS="E">
<textElement ID="R" ENTRY="abap2xlsx Demo: Alignment" LENGTH="26 "/>
<textElement ID="S" KEY="P_PATH" ENTRY="D ." LENGTH="9 "/>
</language>
</textPool>
<source>*&amp;---------------------------------------------------------------------*
*&amp; Report ZDEMO_EXCEL14
*&amp;
*&amp;---------------------------------------------------------------------*
*&amp;
*&amp;
*&amp;---------------------------------------------------------------------*
REPORT zdemo_excel14.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_worksheet TYPE REF TO zcl_excel_worksheet,
lo_style_center TYPE REF TO zcl_excel_style,
lo_style_right TYPE REF TO zcl_excel_style,
lo_style_left TYPE REF TO zcl_excel_style,
lo_style_general TYPE REF TO zcl_excel_style,
lo_style_bottom TYPE REF TO zcl_excel_style,
lo_style_middle TYPE REF TO zcl_excel_style,
lo_style_top TYPE REF TO zcl_excel_style,
lo_style_justify TYPE REF TO zcl_excel_style,
lo_style_mixed TYPE REF TO zcl_excel_style,
lo_style_mixed_wrap TYPE REF TO zcl_excel_style,
lo_style_rotated TYPE REF TO zcl_excel_style,
lo_style_shrink TYPE REF TO zcl_excel_style,
lo_style_indent TYPE REF TO zcl_excel_style,
lv_style_center_guid TYPE zexcel_cell_style,
lv_style_right_guid TYPE zexcel_cell_style,
lv_style_left_guid TYPE zexcel_cell_style,
lv_style_general_guid TYPE zexcel_cell_style,
lv_style_bottom_guid TYPE zexcel_cell_style,
lv_style_middle_guid TYPE zexcel_cell_style,
lv_style_top_guid TYPE zexcel_cell_style,
lv_style_justify_guid TYPE zexcel_cell_style,
lv_style_mixed_guid TYPE zexcel_cell_style,
lv_style_mixed_wrap_guid TYPE zexcel_cell_style,
lv_style_rotated_guid TYPE zexcel_cell_style,
lv_style_shrink_guid TYPE zexcel_cell_style,
lv_style_indent_guid TYPE zexcel_cell_style.
DATA: lo_row_dimension TYPE REF TO zcl_excel_worksheet_rowdimensi.
CONSTANTS: gc_save_file_name TYPE string VALUE &apos;14_Alignment.xlsx&apos;.
INCLUDE zdemo_excel_outputopt_incl.
START-OF-SELECTION.
CREATE OBJECT lo_excel.
&quot; Get active sheet
lo_worksheet = lo_excel-&gt;get_active_worksheet( ).
lo_worksheet-&gt;set_title( &apos;sheet1&apos; ).
&quot;Center
lo_style_center = lo_excel-&gt;add_new_style( ).
lo_style_center-&gt;alignment-&gt;horizontal = zcl_excel_style_alignment=&gt;c_horizontal_center.
lv_style_center_guid = lo_style_center-&gt;get_guid( ).
&quot;Right
lo_style_right = lo_excel-&gt;add_new_style( ).
lo_style_right-&gt;alignment-&gt;horizontal = zcl_excel_style_alignment=&gt;c_horizontal_right.
lv_style_right_guid = lo_style_right-&gt;get_guid( ).
&quot;Left
lo_style_left = lo_excel-&gt;add_new_style( ).
lo_style_left-&gt;alignment-&gt;horizontal = zcl_excel_style_alignment=&gt;c_horizontal_left.
lv_style_left_guid = lo_style_left-&gt;get_guid( ).
&quot;General
lo_style_general = lo_excel-&gt;add_new_style( ).
lo_style_general-&gt;alignment-&gt;horizontal = zcl_excel_style_alignment=&gt;c_horizontal_general.
lv_style_general_guid = lo_style_general-&gt;get_guid( ).
&quot;Bottom
lo_style_bottom = lo_excel-&gt;add_new_style( ).
lo_style_bottom-&gt;alignment-&gt;vertical = zcl_excel_style_alignment=&gt;c_vertical_bottom.
lv_style_bottom_guid = lo_style_bottom-&gt;get_guid( ).
&quot;Middle
lo_style_middle = lo_excel-&gt;add_new_style( ).
lo_style_middle-&gt;alignment-&gt;vertical = zcl_excel_style_alignment=&gt;c_vertical_center.
lv_style_middle_guid = lo_style_middle-&gt;get_guid( ).
&quot;Top
lo_style_top = lo_excel-&gt;add_new_style( ).
lo_style_top-&gt;alignment-&gt;vertical = zcl_excel_style_alignment=&gt;c_vertical_top.
lv_style_top_guid = lo_style_top-&gt;get_guid( ).
&quot;Justify
lo_style_justify = lo_excel-&gt;add_new_style( ).
lo_style_justify-&gt;alignment-&gt;vertical = zcl_excel_style_alignment=&gt;c_vertical_justify.
lv_style_justify_guid = lo_style_justify-&gt;get_guid( ).
&quot;Shrink
lo_style_shrink = lo_excel-&gt;add_new_style( ).
lo_style_shrink-&gt;alignment-&gt;shrinktofit = abap_true.
lv_style_shrink_guid = lo_style_shrink-&gt;get_guid( ).
&quot;Indent
lo_style_indent = lo_excel-&gt;add_new_style( ).
lo_style_indent-&gt;alignment-&gt;indent = 5.
lv_style_indent_guid = lo_style_indent-&gt;get_guid( ).
&quot;Middle / Centered / Wrap
lo_style_mixed_wrap = lo_excel-&gt;add_new_style( ).
lo_style_mixed_wrap-&gt;alignment-&gt;horizontal = zcl_excel_style_alignment=&gt;c_horizontal_center.
lo_style_mixed_wrap-&gt;alignment-&gt;vertical = zcl_excel_style_alignment=&gt;c_vertical_center.
lo_style_mixed_wrap-&gt;alignment-&gt;wraptext = abap_true.
lv_style_mixed_wrap_guid = lo_style_mixed_wrap-&gt;get_guid( ).
&quot;Middle / Centered / Wrap
lo_style_mixed = lo_excel-&gt;add_new_style( ).
lo_style_mixed-&gt;alignment-&gt;horizontal = zcl_excel_style_alignment=&gt;c_horizontal_center.
lo_style_mixed-&gt;alignment-&gt;vertical = zcl_excel_style_alignment=&gt;c_vertical_center.
lv_style_mixed_guid = lo_style_mixed-&gt;get_guid( ).
&quot;Center
lo_style_rotated = lo_excel-&gt;add_new_style( ).
lo_style_rotated-&gt;alignment-&gt;horizontal = zcl_excel_style_alignment=&gt;c_horizontal_center.
lo_style_rotated-&gt;alignment-&gt;vertical = zcl_excel_style_alignment=&gt;c_vertical_center.
lo_style_rotated-&gt;alignment-&gt;textrotation = 165. &quot; -75ð == 90ð + 75ð
lv_style_rotated_guid = lo_style_rotated-&gt;get_guid( ).
&quot; Set row size for first 7 rows to 40
DO 7 TIMES.
lo_row_dimension = lo_worksheet-&gt;get_row_dimension( sy-index ).
lo_row_dimension-&gt;set_row_height( 40 ).
ENDDO.
&quot;Horizontal alignment
lo_worksheet-&gt;set_cell( ip_row = 4 ip_column = &apos;B&apos; ip_value = &apos;Centered Text&apos; ip_style = lv_style_center_guid ).
lo_worksheet-&gt;set_cell( ip_row = 5 ip_column = &apos;B&apos; ip_value = &apos;Right Text&apos; ip_style = lv_style_right_guid ).
lo_worksheet-&gt;set_cell( ip_row = 6 ip_column = &apos;B&apos; ip_value = &apos;Left Text&apos; ip_style = lv_style_left_guid ).
lo_worksheet-&gt;set_cell( ip_row = 7 ip_column = &apos;B&apos; ip_value = &apos;General Text&apos; ip_style = lv_style_general_guid ).
&quot; Shrink &amp; indent
lo_worksheet-&gt;set_cell( ip_row = 4 ip_column = &apos;F&apos; ip_value = &apos;Text shrinked&apos; ip_style = lv_style_shrink_guid ).
lo_worksheet-&gt;set_cell( ip_row = 5 ip_column = &apos;F&apos; ip_value = &apos;Text indented&apos; ip_style = lv_style_indent_guid ).
&quot;Vertical alignment
lo_worksheet-&gt;set_cell( ip_row = 4 ip_column = &apos;D&apos; ip_value = &apos;Bottom Text&apos; ip_style = lv_style_bottom_guid ).
lo_worksheet-&gt;set_cell( ip_row = 5 ip_column = &apos;D&apos; ip_value = &apos;Middle Text&apos; ip_style = lv_style_middle_guid ).
lo_worksheet-&gt;set_cell( ip_row = 6 ip_column = &apos;D&apos; ip_value = &apos;Top Text&apos; ip_style = lv_style_top_guid ).
lo_worksheet-&gt;set_cell( ip_row = 7 ip_column = &apos;D&apos; ip_value = &apos;Justify Text&apos; ip_style = lv_style_justify_guid ).
&quot; Wrapped
lo_worksheet-&gt;set_cell( ip_row = 10 ip_column = &apos;B&apos;
ip_value = &apos;This is a wrapped text centered in the middle&apos;
ip_style = lv_style_mixed_wrap_guid ).
&quot; Rotated
lo_worksheet-&gt;set_cell( ip_row = 10 ip_column = &apos;D&apos;
ip_value = &apos;This is a centered text rotated by -75ð&apos;
ip_style = lv_style_rotated_guid ).
&quot; forced line break
DATA: lv_value TYPE string.
CONCATENATE &apos;This is a wrapped text centered in the middle&apos; cl_abap_char_utilities=&gt;cr_lf
&apos;and a manuall line break.&apos; INTO lv_value.
lo_worksheet-&gt;set_cell( ip_row = 11 ip_column = &apos;B&apos;
ip_value = lv_value
ip_style = lv_style_mixed_guid ).
*** Create output
lcl_output=&gt;output( lo_excel ).</source>
</PROG>