mirror of
https://github.com/abap2xlsx/abap2xlsx.git
synced 2025-05-05 21:06:12 +08:00

git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@9 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049
103 lines
4.1 KiB
XML
103 lines
4.1 KiB
XML
<?xml version="1.0" encoding="utf-16"?>
|
|
<PROG NAME="ZDEMO_EXCEL10" VARCL="X" SUBC="1" CNAM="FEMIA" CDAT="20100719" UNAM="VONDRUSKA" UDAT="20100917" VERN="000058" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20100917" STIME="105913" IDATE="20100917" ITIME="105913" UCCHECK="X">
|
|
<textPool>
|
|
<language SPRAS="E">
|
|
<textElement ID="R" ENTRY="Test for excel" LENGTH="14 "/>
|
|
</language>
|
|
</textPool>
|
|
<source>*&---------------------------------------------------------------------*
|
|
*& Report ZIFE_TEST_EXCEL
|
|
*&
|
|
*&---------------------------------------------------------------------*
|
|
*&
|
|
*&
|
|
*&---------------------------------------------------------------------*
|
|
|
|
REPORT zdemo_excel10.
|
|
|
|
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_conditional2 TYPE REF TO zcl_excel_style_conditional,
|
|
column_dimension TYPE REF TO zcl_excel_worksheet_columndime.
|
|
|
|
DATA: lv_file TYPE xstring,
|
|
lv_bytecount TYPE i,
|
|
lt_field_catalog TYPE zexcel_t_fieldcatalog,
|
|
ls_field_catalog TYPE zexcel_s_fieldcatalog,
|
|
ls_table_settings TYPE zexcel_s_table_settings,
|
|
lt_file_tab TYPE STANDARD TABLE OF solisti1.
|
|
|
|
FIELD-SYMBOLS: <fs_field_catalog> TYPE zexcel_s_fieldcatalog.
|
|
|
|
" Creates active sheet
|
|
CREATE OBJECT lo_excel.
|
|
|
|
" Get active sheet
|
|
lo_worksheet = lo_excel->get_active_worksheet( ).
|
|
lo_worksheet->title = 'Internal table'.
|
|
|
|
"Conditional style
|
|
lo_style_conditional2 = lo_worksheet->add_new_conditional_style( ).
|
|
lo_style_conditional2->rule = zcl_excel_style_conditional=>c_rule_iconset.
|
|
lo_style_conditional2->iconset = zcl_excel_style_conditional=>c_iconset_5arrows.
|
|
lo_style_conditional2->priority = 1.
|
|
|
|
DATA lt_test TYPE TABLE OF sflight.
|
|
SELECT * FROM sflight INTO TABLE lt_test.
|
|
|
|
lt_field_catalog = zcl_excel_common=>get_fieldcatalog( ip_table = lt_test ).
|
|
|
|
LOOP AT lt_field_catalog ASSIGNING <fs_field_catalog>.
|
|
CASE <fs_field_catalog>-fieldname.
|
|
WHEN 'CARRID'.
|
|
<fs_field_catalog>-position = 3.
|
|
<fs_field_catalog>-dynpfld = abap_true.
|
|
<fs_field_catalog>-totals_function = zcl_excel_table=>totals_function_count.
|
|
WHEN 'CONNID'.
|
|
<fs_field_catalog>-position = 4.
|
|
<fs_field_catalog>-dynpfld = abap_true.
|
|
WHEN 'FLDATE'.
|
|
<fs_field_catalog>-position = 2.
|
|
<fs_field_catalog>-dynpfld = abap_true.
|
|
WHEN 'PRICE'.
|
|
<fs_field_catalog>-position = 1.
|
|
<fs_field_catalog>-dynpfld = abap_true.
|
|
<fs_field_catalog>-totals_function = zcl_excel_table=>totals_function_sum.
|
|
<fs_field_catalog>-cond_style = lo_style_conditional2.
|
|
WHEN OTHERS.
|
|
<fs_field_catalog>-dynpfld = abap_false.
|
|
ENDCASE.
|
|
ENDLOOP.
|
|
|
|
ls_table_settings-table_style = zcl_excel_table=>builtinstyle_medium5.
|
|
|
|
lo_worksheet->bind_table( ip_table = lt_test
|
|
is_table_settings = ls_table_settings
|
|
it_field_catalog = lt_field_catalog ).
|
|
|
|
column_dimension = lo_worksheet->get_column_dimension( 'D' ). "make date field a bit wider
|
|
column_dimension->set_width( ip_width = 13 ).
|
|
|
|
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.
|
|
|
|
" Save the file
|
|
CALL FUNCTION 'GUI_DOWNLOAD'
|
|
EXPORTING
|
|
bin_filesize = lv_bytecount
|
|
filename = 'C:\iTabFieldCatalog.xlsx'
|
|
filetype = 'BIN'
|
|
TABLES
|
|
data_tab = lt_file_tab.</source>
|
|
</PROG>
|