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

git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@145 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049
177 lines
8.2 KiB
XML
177 lines
8.2 KiB
XML
<?xml version="1.0" encoding="utf-16"?>
|
|
<PROG NAME="ZDEMO_EXCEL22" VARCL="X" SUBC="1" CNAM="FEMIA" CDAT="20101220" UNAM="BCUSER" UDAT="20110218" VERN="000033" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20110218" STIME="010031" IDATE="20110218" ITIME="010031" UCCHECK="X">
|
|
<textPool>
|
|
<language SPRAS="E">
|
|
<textElement ID="R" ENTRY="abap2xlsx Demo: Export internal table" LENGTH="37 "/>
|
|
<textElement ID="S" KEY="P_PATH" ENTRY="D ." LENGTH="9 "/>
|
|
</language>
|
|
</textPool>
|
|
<programDocumentation/>
|
|
<source>*&---------------------------------------------------------------------*
|
|
*& Report ZDEMO_EXCEL22
|
|
*&
|
|
*&---------------------------------------------------------------------*
|
|
*&
|
|
*&
|
|
*&---------------------------------------------------------------------*
|
|
|
|
REPORT zdemo_excel22.
|
|
|
|
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 TYPE REF TO zcl_excel_style,
|
|
lo_style_date TYPE REF TO zcl_excel_style,
|
|
lo_style_editable TYPE REF TO zcl_excel_style,
|
|
lo_data_validation TYPE REF TO zcl_excel_data_validation.
|
|
|
|
DATA: lt_field_catalog TYPE zexcel_t_fieldcatalog,
|
|
ls_table_settings TYPE zexcel_s_table_settings,
|
|
ls_table_settings_out TYPE zexcel_s_table_settings.
|
|
|
|
DATA: lv_file TYPE xstring,
|
|
lv_style_guid TYPE zexcel_cell_style,
|
|
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,
|
|
lv_row TYPE char10.
|
|
|
|
FIELD-SYMBOLS: <fs_field_catalog> TYPE zexcel_s_fieldcatalog.
|
|
|
|
CONSTANTS: lv_default_file_name TYPE string VALUE '22_itab_fieldcatalog.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.
|
|
|
|
" Creates active sheet
|
|
CREATE OBJECT lo_excel.
|
|
|
|
" Get active sheet
|
|
lo_worksheet = lo_excel->get_active_worksheet( ).
|
|
lo_worksheet->set_title( ip_title = 'PN_MASSIVE').
|
|
|
|
DATA lt_test TYPE TABLE OF sflight.
|
|
SELECT * FROM sflight INTO TABLE lt_test.
|
|
|
|
" sheet style (white background)
|
|
lo_style = lo_excel->add_new_style( ).
|
|
lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
|
|
lo_style->fill->fgcolor = zcl_excel_style_color=>c_white.
|
|
lv_style_guid = lo_style->get_guid( ).
|
|
|
|
" Get active sheet
|
|
lo_worksheet = lo_excel->get_active_worksheet( ).
|
|
lo_worksheet->zif_excel_sheet_properties~set_style( lv_style_guid ).
|
|
lo_worksheet->zif_excel_sheet_protection~protected = zif_excel_sheet_protection=>c_protected.
|
|
lo_worksheet->zif_excel_sheet_protection~password = zcl_excel_common=>encrypt_password( 'test' ).
|
|
lo_worksheet->zif_excel_sheet_protection~sheet = zif_excel_sheet_protection=>c_active.
|
|
lo_worksheet->zif_excel_sheet_protection~objects = zif_excel_sheet_protection=>c_active.
|
|
lo_worksheet->zif_excel_sheet_protection~scenarios = zif_excel_sheet_protection=>c_active.
|
|
|
|
" Create cell style for display only fields
|
|
lo_style = lo_excel->add_new_style( ).
|
|
lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
|
|
lo_style->fill->fgcolor = zcl_excel_style_color=>c_gray.
|
|
lo_style->number_format->format_code = zcl_excel_style_number_format=>c_format_text.
|
|
|
|
" Create cell style for display only date field
|
|
lo_style_date = lo_excel->add_new_style( ).
|
|
lo_style_date->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
|
|
lo_style_date->fill->fgcolor = zcl_excel_style_color=>c_gray.
|
|
lo_style_date->number_format->format_code = zcl_excel_style_number_format=>c_format_date_ddmmyyyy.
|
|
|
|
" Create cell style for editable fields
|
|
lo_style_editable = lo_excel->add_new_style( ).
|
|
lo_style_editable->protection->locked = zcl_excel_style_protection=>c_protection_unlocked.
|
|
|
|
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>-style = lo_style->get_guid( ).
|
|
WHEN 'CONNID'.
|
|
<fs_field_catalog>-position = 1.
|
|
<fs_field_catalog>-dynpfld = abap_true.
|
|
<fs_field_catalog>-style = lo_style->get_guid( ).
|
|
WHEN 'FLDATE'.
|
|
<fs_field_catalog>-position = 2.
|
|
<fs_field_catalog>-dynpfld = abap_true.
|
|
<fs_field_catalog>-style = lo_style_date->get_guid( ).
|
|
WHEN 'PRICE'.
|
|
<fs_field_catalog>-position = 4.
|
|
<fs_field_catalog>-dynpfld = abap_true.
|
|
<fs_field_catalog>-style = lo_style_editable->get_guid( ).
|
|
<fs_field_catalog>-totals_function = zcl_excel_table=>totals_function_sum.
|
|
WHEN OTHERS.
|
|
<fs_field_catalog>-dynpfld = abap_false.
|
|
ENDCASE.
|
|
ENDLOOP.
|
|
|
|
ls_table_settings-table_style = zcl_excel_table=>builtinstyle_medium2.
|
|
ls_table_settings-show_row_stripes = abap_true.
|
|
|
|
lo_worksheet->bind_table( EXPORTING
|
|
ip_table = lt_test
|
|
it_field_catalog = lt_field_catalog
|
|
is_table_settings = ls_table_settings
|
|
IMPORTING
|
|
es_table_settings = ls_table_settings_out ).
|
|
|
|
lo_worksheet->freeze_panes( ip_num_rows = 3 ). "freeze column headers when scrolling
|
|
|
|
lo_data_validation = lo_worksheet->add_new_data_validation( ).
|
|
lo_data_validation->type = zcl_excel_data_validation=>c_type_custom.
|
|
lv_row = ls_table_settings_out-top_left_row.
|
|
CONDENSE lv_row.
|
|
CONCATENATE 'ISNUMBER(' ls_table_settings_out-top_left_column lv_row ')' INTO lo_data_validation->formula1.
|
|
lo_data_validation->cell_row = ls_table_settings_out-top_left_row.
|
|
lo_data_validation->cell_column = ls_table_settings_out-top_left_column.
|
|
lo_data_validation->cell_row_to = ls_table_settings_out-bottom_right_row.
|
|
lo_data_validation->cell_column_to = ls_table_settings_out-bottom_right_column.
|
|
|
|
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>
|