mirror of
https://github.com/abap2xlsx/abap2xlsx.git
synced 2025-05-05 15:35:29 +08:00
169 lines
8.1 KiB
XML
169 lines
8.1 KiB
XML
<?xml version="1.0" encoding="utf-16"?>
|
||
<PROG NAME="ZDEMO_EXCEL14" VARCL="X" SUBC="1" CNAM="FEMIA" CDAT="20100817" UNAM="FEMIA" UDAT="20100912" VERN="000038" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20100912" STIME="205336" IDATE="20100912" ITIME="205336" UCCHECK="X">
|
||
<textPool>
|
||
<language SPRAS="E">
|
||
<textElement ID="R" ENTRY="Test for excel" LENGTH="14 "/>
|
||
</language>
|
||
</textPool>
|
||
<source>*&---------------------------------------------------------------------*
|
||
*& Report ZDEMO_EXCEL13
|
||
*&
|
||
*&---------------------------------------------------------------------*
|
||
*& Example by: Alvaro "Blag" Tejada Galindo.
|
||
*&
|
||
*&---------------------------------------------------------------------*
|
||
|
||
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,
|
||
lv_file TYPE xstring,
|
||
lv_bytecount TYPE i,
|
||
lt_file_tab TYPE STANDARD TABLE OF solisti1,
|
||
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.
|
||
|
||
|
||
CREATE OBJECT lo_excel.
|
||
|
||
" Get active sheet
|
||
lo_worksheet = lo_excel->get_active_worksheet( ).
|
||
lo_worksheet->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 table
|
||
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
|
||
EXPORTING
|
||
buffer = lv_file
|
||
IMPORTING
|
||
output_length = lv_bytecount
|
||
TABLES
|
||
binary_tab = lt_file_tab.
|
||
"Save the file
|
||
CALL FUNCTION 'GUI_DOWNLOAD'
|
||
EXPORTING
|
||
bin_filesize = lv_bytecount
|
||
filename = 'C:\Alignment.xlsx'
|
||
filetype = 'BIN'
|
||
TABLES
|
||
data_tab = lt_file_tab.</source>
|
||
</PROG>
|