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

git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@191 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049
128 lines
5.8 KiB
XML
128 lines
5.8 KiB
XML
<?xml version="1.0" encoding="utf-16"?>
|
|
<PROG NAME="ZDEMO_EXCEL5" VARCL="X" SUBC="1" CNAM="FEMIA" CDAT="20100711" UNAM="FEMIA" UDAT="20110528" VERN="000036" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20110530" STIME="111409" IDATE="20110528" ITIME="181955" UCCHECK="X">
|
|
<textPool>
|
|
<language SPRAS="E">
|
|
<textElement ID="R" ENTRY="abap2xlsx Demo: Conditinal formating" LENGTH="36 "/>
|
|
</language>
|
|
</textPool>
|
|
<source>*&---------------------------------------------------------------------*
|
|
*& Report ZDEMO_EXCEL5
|
|
*&
|
|
*&---------------------------------------------------------------------*
|
|
*&
|
|
*&
|
|
*&---------------------------------------------------------------------*
|
|
|
|
REPORT zdemo_excel5.
|
|
|
|
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_conditional TYPE REF TO zcl_excel_style_conditional.
|
|
|
|
DATA: ls_iconset TYPE zexcel_conditional_iconset.
|
|
|
|
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 '05_Conditional.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_style_conditional = lo_worksheet->add_new_conditional_style( ).
|
|
lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset.
|
|
lo_style_conditional->priority = 1.
|
|
|
|
|
|
ls_iconset-iconset = zcl_excel_style_conditional=>c_iconset_3trafficlights2.
|
|
ls_iconset-cfvo1_type = zcl_excel_style_conditional=>c_cfvo_type_percent.
|
|
ls_iconset-cfvo1_value = '0'.
|
|
ls_iconset-cfvo2_type = zcl_excel_style_conditional=>c_cfvo_type_percent.
|
|
ls_iconset-cfvo2_value = '33'.
|
|
ls_iconset-cfvo3_type = zcl_excel_style_conditional=>c_cfvo_type_percent.
|
|
ls_iconset-cfvo3_value = '66'.
|
|
ls_iconset-showvalue = zcl_excel_style_conditional=>c_showvalue_true.
|
|
|
|
lo_style_conditional->mode_iconset = ls_iconset.
|
|
lo_style_conditional->set_range( ip_start_column = 'C'
|
|
ip_start_row = 4
|
|
ip_stop_column = 'C'
|
|
ip_stop_row = 8 ).
|
|
|
|
|
|
lo_worksheet->set_cell( ip_row = 4 ip_column = 'C' ip_value = 100 ).
|
|
lo_worksheet->set_cell( ip_row = 5 ip_column = 'C' ip_value = 1000 ).
|
|
lo_worksheet->set_cell( ip_row = 6 ip_column = 'C' ip_value = 150 ).
|
|
lo_worksheet->set_cell( ip_row = 7 ip_column = 'C' ip_value = 10 ).
|
|
lo_worksheet->set_cell( ip_row = 8 ip_column = 'C' ip_value = 500 ).
|
|
|
|
|
|
lo_style_conditional = lo_worksheet->add_new_conditional_style( ).
|
|
lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset.
|
|
lo_style_conditional->priority = 1.
|
|
ls_iconset-iconset = zcl_excel_style_conditional=>c_iconset_3trafficlights2.
|
|
ls_iconset-showvalue = zcl_excel_style_conditional=>c_showvalue_false.
|
|
lo_style_conditional->mode_iconset = ls_iconset.
|
|
lo_style_conditional->set_range( ip_start_column = 'E'
|
|
ip_start_row = 4
|
|
ip_stop_column = 'E'
|
|
ip_stop_row = 8 ).
|
|
|
|
|
|
lo_worksheet->set_cell( ip_row = 4 ip_column = 'E' ip_value = 100 ).
|
|
lo_worksheet->set_cell( ip_row = 5 ip_column = 'E' ip_value = 1000 ).
|
|
lo_worksheet->set_cell( ip_row = 6 ip_column = 'E' ip_value = 150 ).
|
|
lo_worksheet->set_cell( ip_row = 7 ip_column = 'E' ip_value = 10 ).
|
|
lo_worksheet->set_cell( ip_row = 8 ip_column = 'E' ip_value = 500 ).
|
|
|
|
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>
|