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

git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@191 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049
175 lines
6.2 KiB
XML
175 lines
6.2 KiB
XML
<?xml version="1.0" encoding="utf-16"?>
|
|
<PROG NAME="ZDEMO_EXCEL21" VARCL="X" SUBC="1" CNAM="BCUSER" CDAT="20101127" UNAM="FEMIA" UDAT="20110528" VERN="000043" RSTAT="T" RMAND="000" RLOAD="E" FIXPT="X" SDATE="20110530" STIME="095303" IDATE="20110528" ITIME="181955" UCCHECK="X">
|
|
<textPool>
|
|
<language SPRAS="E">
|
|
<textElement ID="R" ENTRY="abap2xlsx Demo: Backgound Color Picker" LENGTH="38 "/>
|
|
<textElement ID="S" KEY="P_PATH" ENTRY="D ." LENGTH="9 "/>
|
|
</language>
|
|
</textPool>
|
|
<source>*&---------------------------------------------------------------------*
|
|
*& Report ZDEMO_EXCEL21
|
|
*&
|
|
*&---------------------------------------------------------------------*
|
|
*&
|
|
*&
|
|
*&---------------------------------------------------------------------*
|
|
|
|
REPORT zdemo_excel21.
|
|
|
|
TYPES:
|
|
BEGIN OF t_color_style,
|
|
color TYPE zexcel_style_color_argb,
|
|
style TYPE zexcel_cell_style,
|
|
END OF t_color_style.
|
|
|
|
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_filled TYPE REF TO zcl_excel_style.
|
|
|
|
DATA: color_styles TYPE TABLE OF t_color_style.
|
|
|
|
FIELD-SYMBOLS: <color_style> LIKE LINE OF color_styles.
|
|
|
|
CONSTANTS: max TYPE i VALUE 255,
|
|
step TYPE i VALUE 51.
|
|
|
|
DATA: red TYPE i,
|
|
green TYPE i,
|
|
blue TYPE i,
|
|
red_hex(1) TYPE x,
|
|
green_hex(1) TYPE x,
|
|
blue_hex(1) TYPE x,
|
|
red_str TYPE string,
|
|
green_str TYPE string,
|
|
blue_str TYPE string.
|
|
|
|
DATA: color TYPE zexcel_style_color_argb,
|
|
tint TYPE zexcel_style_color_tint.
|
|
|
|
DATA: row TYPE i,
|
|
row_tmp TYPE i,
|
|
column TYPE zexcel_cell_column VALUE 1,
|
|
col_str TYPE zexcel_cell_column_alpha.
|
|
|
|
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 '21_BackgroundColorPicker.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.
|
|
|
|
WHILE red <= max.
|
|
green = 0.
|
|
WHILE green <= max.
|
|
blue = 0.
|
|
WHILE blue <= max.
|
|
red_hex = red.
|
|
red_str = red_hex.
|
|
green_hex = green.
|
|
green_str = green_hex.
|
|
blue_hex = blue.
|
|
blue_str = blue_hex.
|
|
" Create filled
|
|
CONCATENATE 'FF' red_str green_str blue_str INTO color.
|
|
APPEND INITIAL LINE TO color_styles ASSIGNING <color_style>.
|
|
lo_style_filled = lo_excel->add_new_style( ).
|
|
lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
|
|
lo_style_filled->fill->fgcolor-rgb = color.
|
|
<color_style>-color = color.
|
|
<color_style>-style = lo_style_filled->get_guid( ).
|
|
blue = blue + step.
|
|
ENDWHILE.
|
|
green = green + step.
|
|
ENDWHILE.
|
|
red = red + step.
|
|
ENDWHILE.
|
|
" Get active sheet
|
|
lo_worksheet = lo_excel->get_active_worksheet( ).
|
|
lo_worksheet->set_title( 'Color Picker' ).
|
|
LOOP AT color_styles ASSIGNING <color_style>.
|
|
row_tmp = ( max / step + 1 ) * 3.
|
|
IF row = row_tmp.
|
|
row = 0.
|
|
column = column + 1.
|
|
ENDIF.
|
|
row = row + 1.
|
|
col_str = zcl_excel_common=>convert_column2alpha( column ).
|
|
|
|
" Fill the cell and apply one style
|
|
lo_worksheet->set_cell( ip_column = col_str
|
|
ip_row = row
|
|
ip_value = <color_style>-color
|
|
ip_style = <color_style>-style ).
|
|
ENDLOOP.
|
|
|
|
row = row + 2.
|
|
tint = '-0.5'.
|
|
DO 10 TIMES.
|
|
column = 1.
|
|
DO 10 TIMES.
|
|
lo_style_filled = lo_excel->add_new_style( ).
|
|
lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
|
|
lo_style_filled->fill->fgcolor-theme = sy-index - 1.
|
|
lo_style_filled->fill->fgcolor-tint = tint.
|
|
<color_style>-style = lo_style_filled->get_guid( ).
|
|
col_str = zcl_excel_common=>convert_column2alpha( column ).
|
|
lo_worksheet->set_cell_style( ip_column = col_str
|
|
ip_row = row
|
|
ip_style = <color_style>-style ).
|
|
|
|
ADD 1 TO column.
|
|
ENDDO.
|
|
ADD '0.1' TO tint.
|
|
ADD 1 TO row.
|
|
ENDDO.
|
|
|
|
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>
|