mirror of
https://github.com/abap2xlsx/abap2xlsx.git
synced 2025-05-05 18:47:20 +08:00

git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@191 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049
198 lines
9.5 KiB
XML
198 lines
9.5 KiB
XML
<?xml version="1.0" encoding="utf-16"?>
|
||
<PROG NAME="ZDEMO_EXCEL14" VARCL="X" SUBC="1" CNAM="FEMIA" CDAT="20100817" UNAM="FEMIA" UDAT="20110528" VERN="000054" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20110530" STIME="095303" IDATE="20110528" ITIME="181954" UCCHECK="X">
|
||
<textPool>
|
||
<language SPRAS="E">
|
||
<textElement ID="R" ENTRY="abap2xlsx Demo: Alignment" LENGTH="25 "/>
|
||
<textElement ID="S" KEY="P_PATH" ENTRY="D ." LENGTH="9 "/>
|
||
</language>
|
||
</textPool>
|
||
<source>*&---------------------------------------------------------------------*
|
||
*& Report ZDEMO_EXCEL14
|
||
*&
|
||
*&---------------------------------------------------------------------*
|
||
*&
|
||
*&
|
||
*&---------------------------------------------------------------------*
|
||
|
||
REPORT zdemo_excel14.
|
||
|
||
DATA: lo_excel TYPE REF TO zcl_excel,
|
||
lo_excel_writer TYPE REF TO zif_excel_writer,
|
||
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_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_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.
|
||
|
||
DATA: lv_file TYPE xstring,
|
||
lv_bytecount TYPE i,
|
||
lt_file_tab TYPE solix_tab.
|
||
|
||
DATA: lv_full_path TYPE string,
|
||
lv_workdir TYPE string,
|
||
lv_file_separator TYPE c.
|
||
|
||
CONSTANTS: lv_default_file_name TYPE string VALUE '14_Alignment.xlsx'.
|
||
|
||
PARAMETERS: p_path TYPE zexcel_export_dir.
|
||
|
||
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
|
||
lv_workdir = p_path.
|
||
cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir
|
||
CHANGING selected_folder = lv_workdir ).
|
||
p_path = lv_workdir.
|
||
|
||
INITIALIZATION.
|
||
cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ).
|
||
cl_gui_cfw=>flush( ).
|
||
p_path = lv_workdir.
|
||
|
||
START-OF-SELECTION.
|
||
|
||
IF p_path IS INITIAL.
|
||
p_path = lv_workdir.
|
||
ENDIF.
|
||
cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ).
|
||
CONCATENATE p_path lv_file_separator lv_default_file_name INTO lv_full_path.
|
||
|
||
CREATE OBJECT lo_excel.
|
||
|
||
" Get active sheet
|
||
lo_worksheet = lo_excel->get_active_worksheet( ).
|
||
lo_worksheet->set_title( 'sheet1' ).
|
||
|
||
"Center
|
||
lo_style_center = lo_excel->add_new_style( ).
|
||
lo_style_center->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
|
||
lv_style_center_guid = lo_style_center->get_guid( ).
|
||
"Right
|
||
lo_style_right = lo_excel->add_new_style( ).
|
||
lo_style_right->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_right.
|
||
lv_style_right_guid = lo_style_right->get_guid( ).
|
||
"Left
|
||
lo_style_left = lo_excel->add_new_style( ).
|
||
lo_style_left->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_left.
|
||
lv_style_left_guid = lo_style_left->get_guid( ).
|
||
"General
|
||
lo_style_general = lo_excel->add_new_style( ).
|
||
lo_style_general->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_general.
|
||
lv_style_general_guid = lo_style_general->get_guid( ).
|
||
"Bottom
|
||
lo_style_bottom = lo_excel->add_new_style( ).
|
||
lo_style_bottom->alignment->vertical = zcl_excel_style_alignment=>c_vertical_bottom.
|
||
lv_style_bottom_guid = lo_style_bottom->get_guid( ).
|
||
"Middle
|
||
lo_style_middle = lo_excel->add_new_style( ).
|
||
lo_style_middle->alignment->vertical = zcl_excel_style_alignment=>c_vertical_center.
|
||
lv_style_middle_guid = lo_style_middle->get_guid( ).
|
||
"Top
|
||
lo_style_top = lo_excel->add_new_style( ).
|
||
lo_style_top->alignment->vertical = zcl_excel_style_alignment=>c_vertical_top.
|
||
lv_style_top_guid = lo_style_top->get_guid( ).
|
||
"Justify
|
||
lo_style_justify = lo_excel->add_new_style( ).
|
||
lo_style_justify->alignment->vertical = zcl_excel_style_alignment=>c_vertical_justify.
|
||
lv_style_justify_guid = lo_style_justify->get_guid( ).
|
||
|
||
"Shrink
|
||
lo_style_shrink = lo_excel->add_new_style( ).
|
||
lo_style_shrink->alignment->shrinktofit = abap_true.
|
||
lv_style_shrink_guid = lo_style_shrink->get_guid( ).
|
||
|
||
"Indent
|
||
lo_style_indent = lo_excel->add_new_style( ).
|
||
lo_style_indent->alignment->indent = 5.
|
||
lv_style_indent_guid = lo_style_indent->get_guid( ).
|
||
|
||
"Middle / Centered / Wrap
|
||
lo_style_mixed = lo_excel->add_new_style( ).
|
||
lo_style_mixed->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
|
||
lo_style_mixed->alignment->vertical = zcl_excel_style_alignment=>c_vertical_center.
|
||
lo_style_mixed->alignment->wraptext = abap_true.
|
||
lv_style_mixed_guid = lo_style_mixed->get_guid( ).
|
||
|
||
"Center
|
||
lo_style_rotated = lo_excel->add_new_style( ).
|
||
lo_style_rotated->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
|
||
lo_style_rotated->alignment->vertical = zcl_excel_style_alignment=>c_vertical_center.
|
||
lo_style_rotated->alignment->textrotation = 165. " -75<37> == 90<39> + 75<37>
|
||
lv_style_rotated_guid = lo_style_rotated->get_guid( ).
|
||
|
||
|
||
" Set row size for first 7 rows to 40
|
||
DO 7 TIMES.
|
||
lo_row_dimension = lo_worksheet->get_row_dimension( sy-index ).
|
||
lo_row_dimension->set_row_height( 40 ).
|
||
ENDDO.
|
||
|
||
"Horizontal alignment
|
||
lo_worksheet->set_cell( ip_row = 4 ip_column = 'B' ip_value = 'Centered Text' ip_style = lv_style_center_guid ).
|
||
lo_worksheet->set_cell( ip_row = 5 ip_column = 'B' ip_value = 'Right Text' ip_style = lv_style_right_guid ).
|
||
lo_worksheet->set_cell( ip_row = 6 ip_column = 'B' ip_value = 'Left Text' ip_style = lv_style_left_guid ).
|
||
lo_worksheet->set_cell( ip_row = 7 ip_column = 'B' ip_value = 'General Text' ip_style = lv_style_general_guid ).
|
||
|
||
" Shrink & indent
|
||
lo_worksheet->set_cell( ip_row = 4 ip_column = 'F' ip_value = 'Text shrinked' ip_style = lv_style_shrink_guid ).
|
||
lo_worksheet->set_cell( ip_row = 5 ip_column = 'F' ip_value = 'Text indented' ip_style = lv_style_indent_guid ).
|
||
|
||
"Vertical alignment
|
||
|
||
lo_worksheet->set_cell( ip_row = 4 ip_column = 'D' ip_value = 'Bottom Text' ip_style = lv_style_bottom_guid ).
|
||
lo_worksheet->set_cell( ip_row = 5 ip_column = 'D' ip_value = 'Middle Text' ip_style = lv_style_middle_guid ).
|
||
lo_worksheet->set_cell( ip_row = 6 ip_column = 'D' ip_value = 'Top Text' ip_style = lv_style_top_guid ).
|
||
lo_worksheet->set_cell( ip_row = 7 ip_column = 'D' ip_value = 'Justify Text' ip_style = lv_style_justify_guid ).
|
||
|
||
" Wrapped
|
||
lo_worksheet->set_cell( ip_row = 10 ip_column = 'B'
|
||
ip_value = 'This is a wrapped text centered in the middle'
|
||
ip_style = lv_style_mixed_guid ).
|
||
|
||
" Rotated
|
||
lo_worksheet->set_cell( ip_row = 10 ip_column = 'D'
|
||
ip_value = 'This is a centered text rotated by -75<37>'
|
||
ip_style = lv_style_rotated_guid ).
|
||
|
||
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
|
||
lv_file = lo_excel_writer->write_file( lo_excel ).
|
||
|
||
" Convert to binary
|
||
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
|
||
EXPORTING
|
||
buffer = lv_file
|
||
IMPORTING
|
||
output_length = lv_bytecount
|
||
TABLES
|
||
binary_tab = lt_file_tab.
|
||
* " This method is only available on AS ABAP > 6.40
|
||
* lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ).
|
||
* lv_bytecount = xstrlen( lv_file ).
|
||
|
||
" Save the file
|
||
cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount
|
||
filename = lv_full_path
|
||
filetype = 'BIN'
|
||
CHANGING data_tab = lt_file_tab ).</source>
|
||
</PROG>
|