mirror of
https://github.com/abap2xlsx/abap2xlsx.git
synced 2025-05-05 13:46:17 +08:00
Ready to test #185
git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@320 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049
This commit is contained in:
parent
cd1b8f99e6
commit
2d5fb26d4e
|
@ -1,359 +1,365 @@
|
||||||
<?xml version="1.0" encoding="utf-16"?>
|
<?xml version="1.0" encoding="utf-16"?>
|
||||||
<PROG NAME="ZDEMO_CALENDAR" VARCL="X" SUBC="1" CNAM="DEVELOPER" CDAT="20111229" UNAM="DEVELOPER" UDAT="20111230" VERN="000116" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20111230" STIME="102417" IDATE="20111230" ITIME="102249" UCCHECK="X">
|
<PROG NAME="ZDEMO_CALENDAR" VARCL="X" SUBC="1" CNAM="DEVELOPER" CDAT="20111229" UNAM="DEVELOPER" UDAT="20120619" VERN="000127" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20120619" STIME="063434" IDATE="20120619" ITIME="063434" UCCHECK="X">
|
||||||
<textPool>
|
<textPool>
|
||||||
<language SPRAS="D">
|
<language SPRAS="D">
|
||||||
<textElement ID="I" KEY="001" ENTRY="KW" LENGTH="4 "/>
|
<textElement ID="I" KEY="001" ENTRY="KW" LENGTH="4 "/>
|
||||||
<textElement ID="I" KEY="002" ENTRY="Erzeugt mit abap2xlsx. Weitere Informationen unter http://abap2xlsx.org." LENGTH="100 "/>
|
<textElement ID="I" KEY="002" ENTRY="Erzeugt mit abap2xlsx. Weitere Informationen unter http://abap2xlsx.org." LENGTH="100 "/>
|
||||||
<textElement ID="R" ENTRY="abap2xlsx Demo: Erzeugen eines Kalenders mit Bildern" LENGTH="70 "/>
|
<textElement ID="R" ENTRY="abap2xlsx Demo: Erzeugen eines Kalenders mit Bildern" LENGTH="70 "/>
|
||||||
</language>
|
</language>
|
||||||
<language SPRAS="E">
|
<language SPRAS="E">
|
||||||
<textElement ID="I" KEY="001" ENTRY="CW" LENGTH="4 "/>
|
<textElement ID="I" KEY="001" ENTRY="CW" LENGTH="4 "/>
|
||||||
<textElement ID="I" KEY="002" ENTRY="Created with abap2xlsx. Find more information at http://abap2xlsx.org." LENGTH="100 "/>
|
<textElement ID="I" KEY="002" ENTRY="Created with abap2xlsx. Find more information at http://abap2xlsx.org." LENGTH="100 "/>
|
||||||
<textElement ID="R" ENTRY="abap2xlsx Demo: Create Calendar with Pictures" LENGTH="45 "/>
|
<textElement ID="R" ENTRY="abap2xlsx Demo: Create Calendar with Pictures" LENGTH="45 "/>
|
||||||
<textElement ID="S" KEY="P_FROM" ENTRY="D ." LENGTH="9 "/>
|
<textElement ID="S" KEY="P_FROM" ENTRY="D ." LENGTH="9 "/>
|
||||||
<textElement ID="S" KEY="P_PATH" ENTRY="D ." LENGTH="9 "/>
|
<textElement ID="S" KEY="P_PATH" ENTRY="D ." LENGTH="9 "/>
|
||||||
<textElement ID="S" KEY="P_TO" ENTRY="D ." LENGTH="9 "/>
|
<textElement ID="S" KEY="P_TO" ENTRY="D ." LENGTH="9 "/>
|
||||||
</language>
|
</language>
|
||||||
</textPool>
|
</textPool>
|
||||||
<source>*&---------------------------------------------------------------------*
|
<source>*&---------------------------------------------------------------------*
|
||||||
*& Report ZDEMO_CALENDAR
|
*& Report ZDEMO_CALENDAR
|
||||||
*& abap2xlsx Demo: Create Calendar with Pictures
|
*& abap2xlsx Demo: Create Calendar with Pictures
|
||||||
*&---------------------------------------------------------------------*
|
*&---------------------------------------------------------------------*
|
||||||
*& This report creates a monthly calendar in the specified date range.
|
*& This report creates a monthly calendar in the specified date range.
|
||||||
*& Each month is put on a seperate worksheet. The pictures for each
|
*& Each month is put on a seperate worksheet. The pictures for each
|
||||||
*& month can be specified in a tab delimited file called "Calendar.txt"
|
*& month can be specified in a tab delimited file called "Calendar.txt"
|
||||||
*& which is saved in the Export Directory. By default this is the SAP
|
*& which is saved in the Export Directory. By default this is the SAP
|
||||||
*& Workdir. The file contains 3 fields:
|
*& Workdir. The file contains 3 fields:
|
||||||
*&
|
*&
|
||||||
*& Month (with leading 0)
|
*& Month (with leading 0)
|
||||||
*& Image Filename
|
*& Image Filename
|
||||||
*& Image Description
|
*& Image Description
|
||||||
*&
|
*&
|
||||||
*& The Images should be landscape JPEG's with a 3:2 ratio and min.
|
*& The Images should be landscape JPEG's with a 3:2 ratio and min.
|
||||||
*& 450 pixel height. They must also be saved in the Export Directory.
|
*& 450 pixel height. They must also be saved in the Export Directory.
|
||||||
*& In my tests I've discovered a limit of 20 MB in the
|
*& In my tests I've discovered a limit of 20 MB in the
|
||||||
*& cl_gui_frontend_services=>gui_download method. So keep your images
|
*& cl_gui_frontend_services=>gui_download method. So keep your images
|
||||||
*& smaller or chnage to a server export using OPEN DATASET.
|
*& smaller or chnage to a server export using OPEN DATASET.
|
||||||
*&---------------------------------------------------------------------*
|
*&---------------------------------------------------------------------*
|
||||||
|
|
||||||
REPORT zdemo_calendar.
|
REPORT zdemo_calendar.
|
||||||
|
|
||||||
TYPE-POOLS: abap.
|
TYPE-POOLS: abap.
|
||||||
INCLUDE zdemo_calendar_classes.
|
INCLUDE zdemo_calendar_classes.
|
||||||
|
|
||||||
DATA: lv_workdir TYPE string.
|
DATA: lv_workdir TYPE string.
|
||||||
|
|
||||||
PARAMETERS: p_path TYPE zexcel_export_dir.
|
PARAMETERS: p_path TYPE zexcel_export_dir.
|
||||||
PARAMETERS: p_from TYPE demo_cr_date_from DEFAULT '20120101',
|
PARAMETERS: p_from TYPE dfrom DEFAULT '20120101',
|
||||||
p_to TYPE demo_cr_date_to DEFAULT '20121231'.
|
p_to TYPE dto DEFAULT '20121231'.
|
||||||
|
|
||||||
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
|
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
|
||||||
lv_workdir = p_path.
|
lv_workdir = p_path.
|
||||||
cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir
|
cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir
|
||||||
CHANGING selected_folder = lv_workdir ).
|
CHANGING selected_folder = lv_workdir ).
|
||||||
p_path = lv_workdir.
|
p_path = lv_workdir.
|
||||||
|
|
||||||
INITIALIZATION.
|
INITIALIZATION.
|
||||||
cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ).
|
cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ).
|
||||||
cl_gui_cfw=>flush( ).
|
cl_gui_cfw=>flush( ).
|
||||||
p_path = lv_workdir.
|
p_path = lv_workdir.
|
||||||
|
|
||||||
START-OF-SELECTION.
|
START-OF-SELECTION.
|
||||||
|
|
||||||
DATA: lo_excel TYPE REF TO zcl_excel,
|
DATA: lo_excel TYPE REF TO zcl_excel,
|
||||||
lo_excel_writer TYPE REF TO zif_excel_writer,
|
lo_excel_writer TYPE REF TO zif_excel_writer,
|
||||||
lo_worksheet TYPE REF TO zcl_excel_worksheet,
|
lo_worksheet TYPE REF TO zcl_excel_worksheet,
|
||||||
lo_drawing TYPE REF TO zcl_excel_drawing.
|
lo_col_dim TYPE REF TO zcl_excel_worksheet_columndime,
|
||||||
|
lo_row_dim TYPE REF TO ZCL_EXCEL_WORKSHEET_ROWDIMENSI,
|
||||||
DATA: lo_style_month TYPE REF TO zcl_excel_style,
|
lo_drawing TYPE REF TO zcl_excel_drawing.
|
||||||
lv_style_month_guid TYPE zexcel_cell_style.
|
|
||||||
DATA: lo_style_border TYPE REF TO zcl_excel_style,
|
DATA: lo_style_month TYPE REF TO zcl_excel_style,
|
||||||
lo_border_dark TYPE REF TO zcl_excel_style_border,
|
lv_style_month_guid TYPE zexcel_cell_style.
|
||||||
lv_style_border_guid TYPE zexcel_cell_style.
|
DATA: lo_style_border TYPE REF TO zcl_excel_style,
|
||||||
DATA: lo_style_center TYPE REF TO zcl_excel_style,
|
lo_border_dark TYPE REF TO zcl_excel_style_border,
|
||||||
lv_style_center_guid TYPE zexcel_cell_style.
|
lv_style_border_guid TYPE zexcel_cell_style.
|
||||||
|
DATA: lo_style_center TYPE REF TO zcl_excel_style,
|
||||||
DATA: lv_file TYPE xstring,
|
lv_style_center_guid TYPE zexcel_cell_style.
|
||||||
lv_bytecount TYPE i,
|
|
||||||
lt_file_tab TYPE solix_tab.
|
DATA: lv_file TYPE xstring,
|
||||||
|
lv_bytecount TYPE i,
|
||||||
DATA: lv_full_path TYPE string,
|
lt_file_tab TYPE solix_tab.
|
||||||
image_descr_path TYPE string,
|
|
||||||
lv_file_separator TYPE c.
|
DATA: lv_full_path TYPE string,
|
||||||
DATA: lv_content TYPE xstring,
|
image_descr_path TYPE string,
|
||||||
width TYPE i.
|
lv_file_separator TYPE c.
|
||||||
|
DATA: lv_content TYPE xstring,
|
||||||
DATA: month TYPE i,
|
width TYPE i.
|
||||||
month_nr TYPE fcmnr,
|
|
||||||
count TYPE i VALUE 1,
|
DATA: month TYPE i,
|
||||||
title TYPE zexcel_sheet_title,
|
month_nr TYPE fcmnr,
|
||||||
value TYPE string,
|
count TYPE i VALUE 1,
|
||||||
image_path TYPE string,
|
title TYPE zexcel_sheet_title,
|
||||||
date_from TYPE datum,
|
value TYPE string,
|
||||||
date_to TYPE datum,
|
image_path TYPE string,
|
||||||
row TYPE zexcel_cell_row,
|
date_from TYPE datum,
|
||||||
to_col TYPE zexcel_cell_column_alpha,
|
date_to TYPE datum,
|
||||||
to_col_int TYPE i.
|
row TYPE zexcel_cell_row,
|
||||||
|
to_col TYPE zexcel_cell_column_alpha,
|
||||||
DATA: month_names TYPE TABLE OF t247.
|
to_col_int TYPE i.
|
||||||
FIELD-SYMBOLS: <month_name> LIKE LINE OF month_names.
|
|
||||||
|
DATA: month_names TYPE TABLE OF t247.
|
||||||
TYPES: BEGIN OF tt_datatab,
|
FIELD-SYMBOLS: <month_name> LIKE LINE OF month_names.
|
||||||
month_nr TYPE fcmnr,
|
|
||||||
filename TYPE string,
|
TYPES: BEGIN OF tt_datatab,
|
||||||
descr TYPE string,
|
month_nr TYPE fcmnr,
|
||||||
END OF tt_datatab.
|
filename TYPE string,
|
||||||
|
descr TYPE string,
|
||||||
DATA: image_descriptions TYPE TABLE OF tt_datatab.
|
END OF tt_datatab.
|
||||||
FIELD-SYMBOLS: <img_descr> LIKE LINE OF image_descriptions.
|
|
||||||
|
DATA: image_descriptions TYPE TABLE OF tt_datatab.
|
||||||
CONSTANTS: lv_default_file_name TYPE string VALUE 'Calendar', "#EC NOTEXT
|
FIELD-SYMBOLS: <img_descr> LIKE LINE OF image_descriptions.
|
||||||
from_row TYPE zexcel_cell_row VALUE 28,
|
|
||||||
from_col TYPE zexcel_cell_column_alpha VALUE 'C',
|
CONSTANTS: lv_default_file_name TYPE string VALUE 'Calendar', "#EC NOTEXT
|
||||||
c_height TYPE i VALUE 450, " Image Height
|
from_row TYPE zexcel_cell_row VALUE 28,
|
||||||
c_factor TYPE f VALUE '1.5'. " Image Ratio, default 3:2
|
from_col TYPE zexcel_cell_column_alpha VALUE 'C',
|
||||||
|
c_height TYPE i VALUE 450, " Image Height
|
||||||
IF p_path IS INITIAL.
|
c_factor TYPE f VALUE '1.5'. " Image Ratio, default 3:2
|
||||||
p_path = lv_workdir.
|
|
||||||
ENDIF.
|
IF p_path IS INITIAL.
|
||||||
cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ).
|
p_path = lv_workdir.
|
||||||
CONCATENATE p_path lv_file_separator lv_default_file_name '.xlsx' INTO lv_full_path. "#EC NOTEXT
|
ENDIF.
|
||||||
|
cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ).
|
||||||
" Read Image Names for Month and Description
|
CONCATENATE p_path lv_file_separator lv_default_file_name '.xlsx' INTO lv_full_path. "#EC NOTEXT
|
||||||
CONCATENATE p_path lv_file_separator lv_default_file_name '.txt' INTO image_descr_path. "#EC NOTEXT
|
|
||||||
cl_gui_frontend_services=>gui_upload(
|
" Read Image Names for Month and Description
|
||||||
EXPORTING
|
CONCATENATE p_path lv_file_separator lv_default_file_name '.txt' INTO image_descr_path. "#EC NOTEXT
|
||||||
filename = image_descr_path " Name of file
|
cl_gui_frontend_services=>gui_upload(
|
||||||
filetype = 'ASC' " File Type (ASCII, Binary)
|
EXPORTING
|
||||||
has_field_separator = 'X'
|
filename = image_descr_path " Name of file
|
||||||
read_by_line = 'X' " File Written Line-By-Line to the Internal Table
|
filetype = 'ASC' " File Type (ASCII, Binary)
|
||||||
CHANGING
|
has_field_separator = 'X'
|
||||||
data_tab = image_descriptions " Transfer table for file contents
|
read_by_line = 'X' " File Written Line-By-Line to the Internal Table
|
||||||
EXCEPTIONS
|
CHANGING
|
||||||
file_open_error = 1
|
data_tab = image_descriptions " Transfer table for file contents
|
||||||
file_read_error = 2
|
EXCEPTIONS
|
||||||
no_batch = 3
|
file_open_error = 1
|
||||||
gui_refuse_filetransfer = 4
|
file_read_error = 2
|
||||||
invalid_type = 5
|
no_batch = 3
|
||||||
no_authority = 6
|
gui_refuse_filetransfer = 4
|
||||||
unknown_error = 7
|
invalid_type = 5
|
||||||
bad_data_format = 8
|
no_authority = 6
|
||||||
header_not_allowed = 9
|
unknown_error = 7
|
||||||
separator_not_allowed = 10
|
bad_data_format = 8
|
||||||
header_too_long = 11
|
header_not_allowed = 9
|
||||||
unknown_dp_error = 12
|
separator_not_allowed = 10
|
||||||
access_denied = 13
|
header_too_long = 11
|
||||||
dp_out_of_memory = 14
|
unknown_dp_error = 12
|
||||||
disk_full = 15
|
access_denied = 13
|
||||||
dp_timeout = 16
|
dp_out_of_memory = 14
|
||||||
not_supported_by_gui = 17
|
disk_full = 15
|
||||||
error_no_gui = 18
|
dp_timeout = 16
|
||||||
OTHERS = 19
|
not_supported_by_gui = 17
|
||||||
).
|
error_no_gui = 18
|
||||||
IF sy-subrc <> 0.
|
OTHERS = 19
|
||||||
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
|
).
|
||||||
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
|
IF sy-subrc <> 0.
|
||||||
ENDIF.
|
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
|
||||||
|
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
|
||||||
" Creates active sheet
|
ENDIF.
|
||||||
CREATE OBJECT lo_excel.
|
|
||||||
|
" Creates active sheet
|
||||||
" Create Styles
|
CREATE OBJECT lo_excel.
|
||||||
" Create an underline double style
|
|
||||||
lo_style_month = lo_excel->add_new_style( ).
|
" Create Styles
|
||||||
" lo_style_month->font->underline = abap_true.
|
" Create an underline double style
|
||||||
" lo_style_month->font->underline_mode = zcl_excel_style_font=>c_underline_single.
|
lo_style_month = lo_excel->add_new_style( ).
|
||||||
lo_style_month->font->name = zcl_excel_style_font=>c_name_roman.
|
" lo_style_month->font->underline = abap_true.
|
||||||
lo_style_month->font->scheme = zcl_excel_style_font=>c_scheme_none.
|
" lo_style_month->font->underline_mode = zcl_excel_style_font=>c_underline_single.
|
||||||
lo_style_month->font->family = zcl_excel_style_font=>c_family_roman.
|
lo_style_month->font->name = zcl_excel_style_font=>c_name_roman.
|
||||||
lo_style_month->font->bold = abap_true.
|
lo_style_month->font->scheme = zcl_excel_style_font=>c_scheme_none.
|
||||||
lo_style_month->font->size = 36.
|
lo_style_month->font->family = zcl_excel_style_font=>c_family_roman.
|
||||||
lv_style_month_guid = lo_style_month->get_guid( ).
|
lo_style_month->font->bold = abap_true.
|
||||||
" Create border object
|
lo_style_month->font->size = 36.
|
||||||
CREATE OBJECT lo_border_dark.
|
lv_style_month_guid = lo_style_month->get_guid( ).
|
||||||
lo_border_dark->border_color-rgb = zcl_excel_style_color=>c_black.
|
" Create border object
|
||||||
lo_border_dark->border_style = zcl_excel_style_border=>c_border_thin.
|
CREATE OBJECT lo_border_dark.
|
||||||
"Create style with border
|
lo_border_dark->border_color-rgb = zcl_excel_style_color=>c_black.
|
||||||
lo_style_border = lo_excel->add_new_style( ).
|
lo_border_dark->border_style = zcl_excel_style_border=>c_border_thin.
|
||||||
lo_style_border->borders->allborders = lo_border_dark.
|
"Create style with border
|
||||||
lo_style_border->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_right.
|
lo_style_border = lo_excel->add_new_style( ).
|
||||||
lo_style_border->alignment->vertical = zcl_excel_style_alignment=>c_vertical_top.
|
lo_style_border->borders->allborders = lo_border_dark.
|
||||||
lv_style_border_guid = lo_style_border->get_guid( ).
|
lo_style_border->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_right.
|
||||||
"Create style alignment center
|
lo_style_border->alignment->vertical = zcl_excel_style_alignment=>c_vertical_top.
|
||||||
lo_style_center = lo_excel->add_new_style( ).
|
lv_style_border_guid = lo_style_border->get_guid( ).
|
||||||
lo_style_center->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
|
"Create style alignment center
|
||||||
lo_style_center->alignment->vertical = zcl_excel_style_alignment=>c_vertical_top.
|
lo_style_center = lo_excel->add_new_style( ).
|
||||||
lv_style_center_guid = lo_style_center->get_guid( ).
|
lo_style_center->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
|
||||||
|
lo_style_center->alignment->vertical = zcl_excel_style_alignment=>c_vertical_top.
|
||||||
|
lv_style_center_guid = lo_style_center->get_guid( ).
|
||||||
" Get Month Names
|
|
||||||
CALL FUNCTION 'MONTH_NAMES_GET'
|
|
||||||
TABLES
|
" Get Month Names
|
||||||
month_names = month_names.
|
CALL FUNCTION 'MONTH_NAMES_GET'
|
||||||
|
TABLES
|
||||||
zcl_date_calculation=>months_between_two_dates(
|
month_names = month_names.
|
||||||
EXPORTING
|
|
||||||
i_date_from = p_from
|
zcl_date_calculation=>months_between_two_dates(
|
||||||
i_date_to = p_to
|
EXPORTING
|
||||||
i_incl_to = abap_true
|
i_date_from = p_from
|
||||||
IMPORTING
|
i_date_to = p_to
|
||||||
e_month = month
|
i_incl_to = abap_true
|
||||||
).
|
IMPORTING
|
||||||
|
e_month = month
|
||||||
date_from = p_from.
|
).
|
||||||
|
|
||||||
WHILE count <= month.
|
date_from = p_from.
|
||||||
IF count = 1.
|
|
||||||
" Get active sheet
|
WHILE count <= month.
|
||||||
lo_worksheet = lo_excel->get_active_worksheet( ).
|
IF count = 1.
|
||||||
ELSE.
|
" Get active sheet
|
||||||
lo_worksheet = lo_excel->add_new_worksheet( ).
|
lo_worksheet = lo_excel->get_active_worksheet( ).
|
||||||
ENDIF.
|
ELSE.
|
||||||
|
lo_worksheet = lo_excel->add_new_worksheet( ).
|
||||||
lo_worksheet->zif_excel_sheet_properties~selected = zif_excel_sheet_properties=>c_selected.
|
ENDIF.
|
||||||
|
|
||||||
title = count.
|
lo_worksheet->zif_excel_sheet_properties~selected = zif_excel_sheet_properties=>c_selected.
|
||||||
value = count.
|
|
||||||
CONDENSE title.
|
title = count.
|
||||||
CONDENSE value.
|
value = count.
|
||||||
lo_worksheet->set_title( title ).
|
CONDENSE title.
|
||||||
lo_worksheet->set_print_gridlines( abap_false ).
|
CONDENSE value.
|
||||||
lo_worksheet->sheet_setup->paper_size = zcl_excel_sheet_setup=>c_papersize_a4.
|
lo_worksheet->set_title( title ).
|
||||||
lo_worksheet->sheet_setup->margin_top = '0.80'.
|
lo_worksheet->set_print_gridlines( abap_false ).
|
||||||
lo_worksheet->sheet_setup->margin_left = '0.55'.
|
lo_worksheet->sheet_setup->paper_size = zcl_excel_sheet_setup=>c_papersize_a4.
|
||||||
lo_worksheet->sheet_setup->margin_right = '0.05'.
|
lo_worksheet->sheet_setup->margin_top = '0.80'.
|
||||||
lo_worksheet->sheet_setup->margin_bottom = '0.30'.
|
lo_worksheet->sheet_setup->margin_left = '0.55'.
|
||||||
lo_worksheet->get_column_dimension( 'A' )->set_width( '1.0' ).
|
lo_worksheet->sheet_setup->margin_right = '0.05'.
|
||||||
lo_worksheet->get_column_dimension( 'B' )->set_width( '2.0' ).
|
lo_worksheet->sheet_setup->margin_bottom = '0.30'.
|
||||||
lo_worksheet->get_column_dimension( 'K' )->set_width( '3.0' ).
|
lo_col_dim = lo_worksheet->get_column_dimension( 'A' ).
|
||||||
lo_worksheet->sheet_setup->horizontal_centered = abap_true.
|
lo_col_dim->set_width( '1.0' ).
|
||||||
|
lo_col_dim = lo_worksheet->get_column_dimension( 'B' ).
|
||||||
" Add Month Name
|
lo_col_dim->set_width( '2.0' ).
|
||||||
month_nr = date_from+4(2).
|
lo_col_dim = lo_worksheet->get_column_dimension( 'K' ).
|
||||||
READ TABLE month_names WITH KEY mnr = month_nr ASSIGNING <month_name>.
|
lo_col_dim->set_width( '3.0' ).
|
||||||
CONCATENATE <month_name>-ltx ` ` date_from(4) INTO value.
|
lo_worksheet->sheet_setup->horizontal_centered = abap_true.
|
||||||
row = from_row - 2.
|
|
||||||
lo_worksheet->set_cell(
|
" Add Month Name
|
||||||
EXPORTING
|
month_nr = date_from+4(2).
|
||||||
ip_column = from_col " Cell Column
|
READ TABLE month_names WITH KEY mnr = month_nr ASSIGNING <month_name>.
|
||||||
ip_row = row " Cell Row
|
CONCATENATE <month_name>-ltx ` ` date_from(4) INTO value.
|
||||||
ip_value = value " Cell Value
|
row = from_row - 2.
|
||||||
ip_style = lv_style_month_guid
|
lo_worksheet->set_cell(
|
||||||
).
|
EXPORTING
|
||||||
|
ip_column = from_col " Cell Column
|
||||||
to_col_int = zcl_excel_common=>convert_column2int( from_col ).
|
ip_row = row " Cell Row
|
||||||
to_col = zcl_excel_common=>convert_column2alpha( to_col_int + 7 ).
|
ip_value = value " Cell Value
|
||||||
|
ip_style = lv_style_month_guid
|
||||||
lo_worksheet->set_merge(
|
).
|
||||||
EXPORTING
|
|
||||||
ip_column_start = from_col " Cell Column Start
|
to_col_int = zcl_excel_common=>convert_column2int( from_col ) + 7.
|
||||||
ip_column_end = to_col " Cell Column End
|
to_col = zcl_excel_common=>convert_column2alpha( to_col_int ).
|
||||||
ip_row = row " Cell Row
|
|
||||||
ip_row_to = row " Cell Row
|
lo_worksheet->set_merge(
|
||||||
).
|
EXPORTING
|
||||||
|
ip_column_start = from_col " Cell Column Start
|
||||||
" Add drawing from a XSTRING read from a file
|
ip_column_end = to_col " Cell Column End
|
||||||
UNASSIGN <img_descr>.
|
ip_row = row " Cell Row
|
||||||
READ TABLE image_descriptions WITH KEY month_nr = month_nr ASSIGNING <img_descr>.
|
ip_row_to = row " Cell Row
|
||||||
IF <img_descr> IS ASSIGNED.
|
).
|
||||||
value = <img_descr>-descr.
|
|
||||||
row = from_row - 4.
|
" Add drawing from a XSTRING read from a file
|
||||||
lo_worksheet->set_cell(
|
UNASSIGN <img_descr>.
|
||||||
EXPORTING
|
READ TABLE image_descriptions WITH KEY month_nr = month_nr ASSIGNING <img_descr>.
|
||||||
ip_column = from_col " Cell Column
|
IF <img_descr> IS ASSIGNED.
|
||||||
ip_row = row " Cell Row
|
value = <img_descr>-descr.
|
||||||
ip_value = value " Cell Value
|
row = from_row - 3.
|
||||||
).
|
lo_worksheet->set_cell(
|
||||||
lo_worksheet->get_row_dimension( row )->set_row_height( '18.0' ).
|
EXPORTING
|
||||||
|
ip_column = from_col " Cell Column
|
||||||
CONCATENATE p_path lv_file_separator <img_descr>-filename INTO image_path.
|
ip_row = row " Cell Row
|
||||||
lo_drawing = lo_excel->add_new_drawing( ).
|
ip_value = value " Cell Value
|
||||||
lo_drawing->set_position( ip_from_row = 1
|
).
|
||||||
ip_from_col = 'B' ).
|
lo_row_dim = lo_worksheet->get_row_dimension( row ).
|
||||||
|
lo_row_dim->set_row_height( '22.0' ).
|
||||||
lv_content = zcl_helper=>load_image( image_path ).
|
|
||||||
width = c_height * c_factor.
|
CONCATENATE p_path lv_file_separator <img_descr>-filename INTO image_path.
|
||||||
lo_drawing->set_media( ip_media = lv_content
|
lo_drawing = lo_excel->add_new_drawing( ).
|
||||||
ip_media_type = 'jpg'
|
lo_drawing->set_position( ip_from_row = 1
|
||||||
ip_width = width
|
ip_from_col = 'B' ).
|
||||||
ip_height = c_height ).
|
|
||||||
lo_worksheet->add_drawing( lo_drawing ).
|
lv_content = zcl_helper=>load_image( image_path ).
|
||||||
ENDIF.
|
width = c_height * c_factor.
|
||||||
|
lo_drawing->set_media( ip_media = lv_content
|
||||||
" Add Calendar
|
ip_media_type = 'jpg'
|
||||||
CALL FUNCTION 'SLS_MISC_GET_LAST_DAY_OF_MONTH'
|
ip_width = width
|
||||||
EXPORTING
|
ip_height = c_height ).
|
||||||
day_in = date_from
|
lo_worksheet->add_drawing( lo_drawing ).
|
||||||
IMPORTING
|
ENDIF.
|
||||||
last_day_of_month = date_to.
|
|
||||||
|
" Add Calendar
|
||||||
zcl_helper=>add_calendar(
|
CALL FUNCTION 'SLS_MISC_GET_LAST_DAY_OF_MONTH'
|
||||||
EXPORTING
|
EXPORTING
|
||||||
i_date_from = date_from
|
day_in = date_from
|
||||||
i_date_to = date_to
|
IMPORTING
|
||||||
i_from_row = from_row
|
last_day_of_month = date_to.
|
||||||
i_from_col = from_col
|
|
||||||
i_day_style = lv_style_border_guid
|
zcl_helper=>add_calendar(
|
||||||
i_cw_style = lv_style_center_guid
|
EXPORTING
|
||||||
CHANGING
|
i_date_from = date_from
|
||||||
c_worksheet = lo_worksheet
|
i_date_to = date_to
|
||||||
).
|
i_from_row = from_row
|
||||||
|
i_from_col = from_col
|
||||||
count = count + 1.
|
i_day_style = lv_style_border_guid
|
||||||
date_from = date_to + 1.
|
i_cw_style = lv_style_center_guid
|
||||||
ENDWHILE.
|
CHANGING
|
||||||
|
c_worksheet = lo_worksheet
|
||||||
lo_excel->set_active_sheet_index_by_name( '1' ).
|
).
|
||||||
|
|
||||||
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
|
count = count + 1.
|
||||||
lv_file = lo_excel_writer->write_file( lo_excel ).
|
date_from = date_to + 1.
|
||||||
|
ENDWHILE.
|
||||||
" Convert to binary
|
|
||||||
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
|
lo_excel->set_active_sheet_index_by_name( '1' ).
|
||||||
EXPORTING
|
|
||||||
buffer = lv_file
|
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
|
||||||
IMPORTING
|
lv_file = lo_excel_writer->write_file( lo_excel ).
|
||||||
output_length = lv_bytecount
|
|
||||||
TABLES
|
" Convert to binary
|
||||||
binary_tab = lt_file_tab.
|
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
|
||||||
* " This method is only available on AS ABAP > 6.40
|
EXPORTING
|
||||||
* lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ).
|
buffer = lv_file
|
||||||
* lv_bytecount = xstrlen( lv_file ).
|
IMPORTING
|
||||||
|
output_length = lv_bytecount
|
||||||
" Save the file
|
TABLES
|
||||||
cl_gui_frontend_services=>gui_download(
|
binary_tab = lt_file_tab.
|
||||||
EXPORTING bin_filesize = lv_bytecount
|
* " This method is only available on AS ABAP > 6.40
|
||||||
filename = lv_full_path
|
* lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ).
|
||||||
filetype = 'BIN'
|
* lv_bytecount = xstrlen( lv_file ).
|
||||||
CHANGING data_tab = lt_file_tab
|
|
||||||
EXCEPTIONS
|
" Save the file
|
||||||
file_write_error = 1
|
cl_gui_frontend_services=>gui_download(
|
||||||
no_batch = 2
|
EXPORTING bin_filesize = lv_bytecount
|
||||||
gui_refuse_filetransfer = 3
|
filename = lv_full_path
|
||||||
invalid_type = 4
|
filetype = 'BIN'
|
||||||
no_authority = 5
|
CHANGING data_tab = lt_file_tab
|
||||||
unknown_error = 6
|
EXCEPTIONS
|
||||||
header_not_allowed = 7
|
file_write_error = 1
|
||||||
separator_not_allowed = 8
|
no_batch = 2
|
||||||
filesize_not_allowed = 9
|
gui_refuse_filetransfer = 3
|
||||||
header_too_long = 10
|
invalid_type = 4
|
||||||
dp_error_create = 11
|
no_authority = 5
|
||||||
dp_error_send = 12
|
unknown_error = 6
|
||||||
dp_error_write = 13
|
header_not_allowed = 7
|
||||||
unknown_dp_error = 14
|
separator_not_allowed = 8
|
||||||
access_denied = 15
|
filesize_not_allowed = 9
|
||||||
dp_out_of_memory = 16
|
header_too_long = 10
|
||||||
disk_full = 17
|
dp_error_create = 11
|
||||||
dp_timeout = 18
|
dp_error_send = 12
|
||||||
file_not_found = 19
|
dp_error_write = 13
|
||||||
dataprovider_exception = 20
|
unknown_dp_error = 14
|
||||||
control_flush_error = 21
|
access_denied = 15
|
||||||
not_supported_by_gui = 22
|
dp_out_of_memory = 16
|
||||||
error_no_gui = 23
|
disk_full = 17
|
||||||
OTHERS = 24
|
dp_timeout = 18
|
||||||
).
|
file_not_found = 19
|
||||||
IF sy-subrc <> 0.
|
dataprovider_exception = 20
|
||||||
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
|
control_flush_error = 21
|
||||||
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
|
not_supported_by_gui = 22
|
||||||
ENDIF.</source>
|
error_no_gui = 23
|
||||||
</PROG>
|
OTHERS = 24
|
||||||
|
).
|
||||||
|
IF sy-subrc <> 0.
|
||||||
|
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
|
||||||
|
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
|
||||||
|
ENDIF.</source>
|
||||||
|
</PROG>
|
||||||
|
|
|
@ -1,348 +1,358 @@
|
||||||
<?xml version="1.0" encoding="utf-16"?>
|
<?xml version="1.0" encoding="utf-16"?>
|
||||||
<PROG NAME="ZDEMO_CALENDAR_CLASSES" VARCL="X" SUBC="I" CNAM="DEVELOPER" CDAT="20111229" UNAM="DEVELOPER" UDAT="20111230" VERN="000057" RMAND="001" RLOAD="E" SDATE="20111230" STIME="102417" IDATE="20111230" ITIME="102417" UCCHECK="X">
|
<PROG NAME="ZDEMO_CALENDAR_CLASSES" VARCL="X" SUBC="I" CNAM="DEVELOPER" CDAT="20111229" UNAM="DEVELOPER" UDAT="20120619" VERN="000062" RMAND="001" RLOAD="E" SDATE="20120619" STIME="060152" IDATE="20120619" ITIME="060152" UCCHECK="X">
|
||||||
<textPool>
|
<textPool>
|
||||||
<language SPRAS="E">
|
<language SPRAS="E">
|
||||||
<textElement ID="R" ENTRY="Include ZDEMO_CALENDAR_CLASSES" LENGTH="30 "/>
|
<textElement ID="R" ENTRY="Include ZDEMO_CALENDAR_CLASSES" LENGTH="30 "/>
|
||||||
</language>
|
</language>
|
||||||
</textPool>
|
</textPool>
|
||||||
<source>*&---------------------------------------------------------------------*
|
<source>*&---------------------------------------------------------------------*
|
||||||
*& Include ZDEMO_CALENDAR_CLASSES
|
*& Include ZDEMO_CALENDAR_CLASSES
|
||||||
*&---------------------------------------------------------------------*
|
*&---------------------------------------------------------------------*
|
||||||
|
|
||||||
*&---------------------------------------------------------------------*
|
*&---------------------------------------------------------------------*
|
||||||
*& Class ZCL_DATE_CALCULATION
|
*& Class ZCL_DATE_CALCULATION
|
||||||
*&---------------------------------------------------------------------*
|
*&---------------------------------------------------------------------*
|
||||||
* Text
|
* Text
|
||||||
*----------------------------------------------------------------------*
|
*----------------------------------------------------------------------*
|
||||||
CLASS zcl_date_calculation DEFINITION.
|
CLASS zcl_date_calculation DEFINITION.
|
||||||
PUBLIC SECTION.
|
PUBLIC SECTION.
|
||||||
CLASS-METHODS: months_between_two_dates
|
CLASS-METHODS: months_between_two_dates
|
||||||
IMPORTING
|
IMPORTING
|
||||||
i_date_from TYPE datum
|
i_date_from TYPE datum
|
||||||
i_date_to TYPE datum
|
i_date_to TYPE datum
|
||||||
i_incl_to TYPE flag
|
i_incl_to TYPE flag
|
||||||
EXPORTING
|
EXPORTING
|
||||||
e_month TYPE i.
|
e_month TYPE i.
|
||||||
ENDCLASS. "ZCL_DATE_CALCULATION
|
ENDCLASS. "ZCL_DATE_CALCULATION
|
||||||
|
|
||||||
|
|
||||||
*----------------------------------------------------------------------*
|
*----------------------------------------------------------------------*
|
||||||
* CLASS ZCL_DATE_CALCULATION IMPLEMENTATION
|
* CLASS ZCL_DATE_CALCULATION IMPLEMENTATION
|
||||||
*----------------------------------------------------------------------*
|
*----------------------------------------------------------------------*
|
||||||
*
|
*
|
||||||
*----------------------------------------------------------------------*
|
*----------------------------------------------------------------------*
|
||||||
CLASS zcl_date_calculation IMPLEMENTATION.
|
CLASS zcl_date_calculation IMPLEMENTATION.
|
||||||
METHOD months_between_two_dates.
|
METHOD months_between_two_dates.
|
||||||
DATA: date_to TYPE datum.
|
DATA: date_to TYPE datum.
|
||||||
DATA: BEGIN OF datum_von,
|
DATA: BEGIN OF datum_von,
|
||||||
jjjj(4) TYPE n,
|
jjjj(4) TYPE n,
|
||||||
mm(2) TYPE n,
|
mm(2) TYPE n,
|
||||||
tt(2) TYPE n,
|
tt(2) TYPE n,
|
||||||
END OF datum_von.
|
END OF datum_von.
|
||||||
|
|
||||||
DATA: BEGIN OF datum_bis,
|
DATA: BEGIN OF datum_bis,
|
||||||
jjjj(4) TYPE n,
|
jjjj(4) TYPE n,
|
||||||
mm(2) TYPE n,
|
mm(2) TYPE n,
|
||||||
tt(2) TYPE n,
|
tt(2) TYPE n,
|
||||||
END OF datum_bis.
|
END OF datum_bis.
|
||||||
|
|
||||||
e_month = 0.
|
e_month = 0.
|
||||||
|
|
||||||
CHECK NOT ( i_date_from IS INITIAL )
|
CHECK NOT ( i_date_from IS INITIAL )
|
||||||
AND NOT ( i_date_to IS INITIAL ).
|
AND NOT ( i_date_to IS INITIAL ).
|
||||||
|
|
||||||
date_to = i_date_to.
|
date_to = i_date_to.
|
||||||
IF i_incl_to = abap_true.
|
IF i_incl_to = abap_true.
|
||||||
date_to = date_to + 1.
|
date_to = date_to + 1.
|
||||||
ENDIF.
|
ENDIF.
|
||||||
|
|
||||||
datum_von = i_date_from.
|
datum_von = i_date_from.
|
||||||
datum_bis = date_to.
|
datum_bis = date_to.
|
||||||
|
|
||||||
e_month = ( datum_bis-jjjj - datum_von-jjjj ) * 12
|
e_month = ( datum_bis-jjjj - datum_von-jjjj ) * 12
|
||||||
+ ( datum_bis-mm - datum_von-mm ).
|
+ ( datum_bis-mm - datum_von-mm ).
|
||||||
ENDMETHOD. "MONTHS_BETWEEN_TWO_DATES
|
ENDMETHOD. "MONTHS_BETWEEN_TWO_DATES
|
||||||
ENDCLASS. "ZCL_DATE_CALCULATION IMPLEMENTATION
|
ENDCLASS. "ZCL_DATE_CALCULATION IMPLEMENTATION
|
||||||
|
|
||||||
*----------------------------------------------------------------------*
|
*----------------------------------------------------------------------*
|
||||||
* CLASS zcl_date_calculation_test DEFINITION
|
* CLASS zcl_date_calculation_test DEFINITION
|
||||||
*----------------------------------------------------------------------*
|
*----------------------------------------------------------------------*
|
||||||
*
|
*
|
||||||
*----------------------------------------------------------------------*
|
*----------------------------------------------------------------------*
|
||||||
CLASS zcl_date_calculation_test DEFINITION FOR TESTING
|
CLASS zcl_date_calculation_test DEFINITION FOR TESTING
|
||||||
RISK LEVEL HARMLESS
|
" DURATION SHORT
|
||||||
DURATION SHORT.
|
" RISK LEVEL HARMLESS
|
||||||
PUBLIC SECTION.
|
"#AU Duration Medium
|
||||||
METHODS:
|
"#AU Risk_Level Harmless
|
||||||
months_between_two_dates FOR TESTING.
|
.
|
||||||
ENDCLASS. "zcl_date_calculation_test DEFINITION
|
PUBLIC SECTION.
|
||||||
*----------------------------------------------------------------------*
|
METHODS:
|
||||||
* CLASS zcl_date_calculation_test IMPLEMENTATION
|
months_between_two_dates FOR TESTING.
|
||||||
*----------------------------------------------------------------------*
|
ENDCLASS. "zcl_date_calculation_test DEFINITION
|
||||||
*
|
*----------------------------------------------------------------------*
|
||||||
*----------------------------------------------------------------------*
|
* CLASS zcl_date_calculation_test IMPLEMENTATION
|
||||||
CLASS zcl_date_calculation_test IMPLEMENTATION.
|
*----------------------------------------------------------------------*
|
||||||
METHOD months_between_two_dates.
|
*
|
||||||
|
*----------------------------------------------------------------------*
|
||||||
DATA: date_from TYPE datum VALUE '20120101',
|
CLASS zcl_date_calculation_test IMPLEMENTATION.
|
||||||
date_to TYPE datum VALUE '20121231'.
|
METHOD months_between_two_dates.
|
||||||
DATA: month TYPE i.
|
|
||||||
|
DATA: date_from TYPE datum VALUE '20120101',
|
||||||
zcl_date_calculation=>months_between_two_dates(
|
date_to TYPE datum VALUE '20121231'.
|
||||||
EXPORTING
|
DATA: month TYPE i.
|
||||||
i_date_from = date_from
|
|
||||||
i_date_to = date_to
|
zcl_date_calculation=>months_between_two_dates(
|
||||||
i_incl_to = abap_true
|
EXPORTING
|
||||||
IMPORTING
|
i_date_from = date_from
|
||||||
e_month = month
|
i_date_to = date_to
|
||||||
).
|
i_incl_to = abap_true
|
||||||
|
IMPORTING
|
||||||
cl_aunit_assert=>assert_equals(
|
e_month = month
|
||||||
exp = 12 " Data Object with Expected Type
|
).
|
||||||
act = month " Data Object with Current Value
|
|
||||||
msg = 'Calculated date is wrong' " Message in Case of Error
|
cl_aunit_assert=>assert_equals(
|
||||||
).
|
exp = 12 " Data Object with Expected Type
|
||||||
|
act = month " Data Object with Current Value
|
||||||
ENDMETHOD. "months_between_two_dates
|
msg = 'Calculated date is wrong' " Message in Case of Error
|
||||||
ENDCLASS. "zcl_date_calculation_test IMPLEMENTATION
|
).
|
||||||
*----------------------------------------------------------------------*
|
|
||||||
* CLASS zcl_helper DEFINITION
|
ENDMETHOD. "months_between_two_dates
|
||||||
*----------------------------------------------------------------------*
|
ENDCLASS. "zcl_date_calculation_test IMPLEMENTATION
|
||||||
*
|
*----------------------------------------------------------------------*
|
||||||
*----------------------------------------------------------------------*
|
* CLASS zcl_helper DEFINITION
|
||||||
CLASS zcl_helper DEFINITION.
|
*----------------------------------------------------------------------*
|
||||||
PUBLIC SECTION.
|
*
|
||||||
CLASS-METHODS:
|
*----------------------------------------------------------------------*
|
||||||
load_image
|
CLASS zcl_helper DEFINITION.
|
||||||
IMPORTING
|
PUBLIC SECTION.
|
||||||
filename TYPE string
|
CLASS-METHODS:
|
||||||
RETURNING value(r_image) TYPE xstring,
|
load_image
|
||||||
add_calendar
|
IMPORTING
|
||||||
IMPORTING
|
filename TYPE string
|
||||||
i_date_from TYPE datum
|
RETURNING value(r_image) TYPE xstring,
|
||||||
i_date_to TYPE datum
|
add_calendar
|
||||||
i_from_row TYPE zexcel_cell_row
|
IMPORTING
|
||||||
i_from_col TYPE zexcel_cell_column_alpha
|
i_date_from TYPE datum
|
||||||
i_day_style TYPE zexcel_cell_style
|
i_date_to TYPE datum
|
||||||
i_cw_style TYPE zexcel_cell_style
|
i_from_row TYPE zexcel_cell_row
|
||||||
CHANGING
|
i_from_col TYPE zexcel_cell_column_alpha
|
||||||
c_worksheet TYPE REF TO zcl_excel_worksheet,
|
i_day_style TYPE zexcel_cell_style
|
||||||
add_calender_week
|
i_cw_style TYPE zexcel_cell_style
|
||||||
IMPORTING
|
CHANGING
|
||||||
i_date TYPE datum
|
c_worksheet TYPE REF TO zcl_excel_worksheet,
|
||||||
i_row TYPE zexcel_cell_row
|
add_calender_week
|
||||||
i_col TYPE zexcel_cell_column_alpha
|
IMPORTING
|
||||||
i_style TYPE zexcel_cell_style
|
i_date TYPE datum
|
||||||
CHANGING
|
i_row TYPE zexcel_cell_row
|
||||||
c_worksheet TYPE REF TO zcl_excel_worksheet.
|
i_col TYPE zexcel_cell_column_alpha
|
||||||
ENDCLASS. "zcl_helper DEFINITION
|
i_style TYPE zexcel_cell_style
|
||||||
|
CHANGING
|
||||||
*----------------------------------------------------------------------*
|
c_worksheet TYPE REF TO zcl_excel_worksheet.
|
||||||
* CLASS zcl_helper IMPLEMENTATION
|
ENDCLASS. "zcl_helper DEFINITION
|
||||||
*----------------------------------------------------------------------*
|
|
||||||
*
|
*----------------------------------------------------------------------*
|
||||||
*----------------------------------------------------------------------*
|
* CLASS zcl_helper IMPLEMENTATION
|
||||||
CLASS zcl_helper IMPLEMENTATION.
|
*----------------------------------------------------------------------*
|
||||||
METHOD load_image.
|
*
|
||||||
"Load samle image
|
*----------------------------------------------------------------------*
|
||||||
DATA: lt_bin TYPE solix_tab,
|
CLASS zcl_helper IMPLEMENTATION.
|
||||||
lv_len TYPE i.
|
METHOD load_image.
|
||||||
|
"Load samle image
|
||||||
CALL METHOD cl_gui_frontend_services=>gui_upload
|
DATA: lt_bin TYPE solix_tab,
|
||||||
EXPORTING
|
lv_len TYPE i.
|
||||||
filename = filename
|
|
||||||
filetype = 'BIN'
|
CALL METHOD cl_gui_frontend_services=>gui_upload
|
||||||
IMPORTING
|
EXPORTING
|
||||||
filelength = lv_len
|
filename = filename
|
||||||
CHANGING
|
filetype = 'BIN'
|
||||||
data_tab = lt_bin
|
IMPORTING
|
||||||
EXCEPTIONS
|
filelength = lv_len
|
||||||
file_open_error = 1
|
CHANGING
|
||||||
file_read_error = 2
|
data_tab = lt_bin
|
||||||
no_batch = 3
|
EXCEPTIONS
|
||||||
gui_refuse_filetransfer = 4
|
file_open_error = 1
|
||||||
invalid_type = 5
|
file_read_error = 2
|
||||||
no_authority = 6
|
no_batch = 3
|
||||||
unknown_error = 7
|
gui_refuse_filetransfer = 4
|
||||||
bad_data_format = 8
|
invalid_type = 5
|
||||||
header_not_allowed = 9
|
no_authority = 6
|
||||||
separator_not_allowed = 10
|
unknown_error = 7
|
||||||
header_too_long = 11
|
bad_data_format = 8
|
||||||
unknown_dp_error = 12
|
header_not_allowed = 9
|
||||||
access_denied = 13
|
separator_not_allowed = 10
|
||||||
dp_out_of_memory = 14
|
header_too_long = 11
|
||||||
disk_full = 15
|
unknown_dp_error = 12
|
||||||
dp_timeout = 16
|
access_denied = 13
|
||||||
not_supported_by_gui = 17
|
dp_out_of_memory = 14
|
||||||
error_no_gui = 18
|
disk_full = 15
|
||||||
OTHERS = 19.
|
dp_timeout = 16
|
||||||
IF sy-subrc <> 0.
|
not_supported_by_gui = 17
|
||||||
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
|
error_no_gui = 18
|
||||||
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
|
OTHERS = 19.
|
||||||
ENDIF.
|
IF sy-subrc <> 0.
|
||||||
|
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
|
||||||
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
|
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
|
||||||
EXPORTING
|
ENDIF.
|
||||||
input_length = lv_len
|
|
||||||
IMPORTING
|
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
|
||||||
buffer = r_image
|
EXPORTING
|
||||||
TABLES
|
input_length = lv_len
|
||||||
binary_tab = lt_bin
|
IMPORTING
|
||||||
EXCEPTIONS
|
buffer = r_image
|
||||||
failed = 1
|
TABLES
|
||||||
OTHERS = 2.
|
binary_tab = lt_bin
|
||||||
IF sy-subrc <> 0.
|
EXCEPTIONS
|
||||||
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
|
failed = 1
|
||||||
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
|
OTHERS = 2.
|
||||||
ENDIF.
|
IF sy-subrc <> 0.
|
||||||
ENDMETHOD. "load_image
|
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
|
||||||
METHOD add_calendar.
|
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
|
||||||
DATA: row TYPE zexcel_cell_row,
|
ENDIF.
|
||||||
col_int TYPE zexcel_cell_column,
|
ENDMETHOD. "load_image
|
||||||
from_col_int TYPE zexcel_cell_column,
|
METHOD add_calendar.
|
||||||
col TYPE zexcel_cell_column_alpha.
|
DATA: row TYPE zexcel_cell_row,
|
||||||
DATA: lv_date TYPE datum,
|
row_max TYPE i,
|
||||||
value TYPE string,
|
col_int TYPE zexcel_cell_column,
|
||||||
weekday TYPE wotnr,
|
col_max TYPE i,
|
||||||
weekrow TYPE wotnr VALUE 1,
|
from_col_int TYPE zexcel_cell_column,
|
||||||
day TYPE i,
|
col TYPE zexcel_cell_column_alpha,
|
||||||
width TYPE f,
|
lr_col_dim TYPE REF TO zcl_excel_worksheet_columndime,
|
||||||
height TYPE f.
|
lr_row_dim TYPE REF TO zcl_excel_worksheet_rowdimensi.
|
||||||
DATA: hyperlink TYPE REF TO zcl_excel_hyperlink.
|
DATA: lv_date TYPE datum,
|
||||||
|
value TYPE string,
|
||||||
DATA: day_names TYPE TABLE OF t246.
|
weekday TYPE wotnr,
|
||||||
FIELD-SYMBOLS: <day_name> LIKE LINE OF day_names.
|
weekrow TYPE wotnr VALUE 1,
|
||||||
|
day TYPE i,
|
||||||
lv_date = i_date_from.
|
width TYPE f,
|
||||||
from_col_int = zcl_excel_common=>convert_column2int( i_from_col ).
|
height TYPE f.
|
||||||
" Add description for Calendar Week
|
DATA: hyperlink TYPE REF TO zcl_excel_hyperlink.
|
||||||
c_worksheet->set_cell(
|
|
||||||
EXPORTING
|
DATA: day_names TYPE TABLE OF t246.
|
||||||
ip_column = i_from_col " Cell Column
|
FIELD-SYMBOLS: <day_name> LIKE LINE OF day_names.
|
||||||
ip_row = i_from_row " Cell Row
|
|
||||||
ip_value = 'CW'(001) " Cell Value
|
lv_date = i_date_from.
|
||||||
ip_style = i_cw_style
|
from_col_int = zcl_excel_common=>convert_column2int( i_from_col ).
|
||||||
).
|
" Add description for Calendar Week
|
||||||
|
c_worksheet->set_cell(
|
||||||
" Add Days
|
EXPORTING
|
||||||
CALL FUNCTION 'DAY_NAMES_GET'
|
ip_column = i_from_col " Cell Column
|
||||||
TABLES
|
ip_row = i_from_row " Cell Row
|
||||||
day_names = day_names.
|
ip_value = 'CW'(001) " Cell Value
|
||||||
|
ip_style = i_cw_style
|
||||||
LOOP AT day_names ASSIGNING <day_name>.
|
).
|
||||||
row = i_from_row.
|
|
||||||
col_int = from_col_int + <day_name>-wotnr.
|
" Add Days
|
||||||
col = zcl_excel_common=>convert_column2alpha( col_int ).
|
CALL FUNCTION 'DAY_NAMES_GET'
|
||||||
value = <day_name>-langt.
|
TABLES
|
||||||
c_worksheet->set_cell(
|
day_names = day_names.
|
||||||
EXPORTING
|
|
||||||
ip_column = col " Cell Column
|
LOOP AT day_names ASSIGNING <day_name>.
|
||||||
ip_row = row " Cell Row
|
row = i_from_row.
|
||||||
ip_value = value " Cell Value
|
col_int = from_col_int + <day_name>-wotnr.
|
||||||
ip_style = i_cw_style
|
col = zcl_excel_common=>convert_column2alpha( col_int ).
|
||||||
).
|
value = <day_name>-langt.
|
||||||
ENDLOOP.
|
c_worksheet->set_cell(
|
||||||
|
EXPORTING
|
||||||
WHILE lv_date <= i_date_to.
|
ip_column = col " Cell Column
|
||||||
day = lv_date+6(2).
|
ip_row = row " Cell Row
|
||||||
CALL FUNCTION 'FIMA_X_DAY_IN_MONTH_COMPUTE'
|
ip_value = value " Cell Value
|
||||||
EXPORTING
|
ip_style = i_cw_style
|
||||||
i_datum = lv_date
|
).
|
||||||
IMPORTING
|
ENDLOOP.
|
||||||
e_wochentag_nr = weekday.
|
|
||||||
|
WHILE lv_date <= i_date_to.
|
||||||
row = i_from_row + weekrow.
|
day = lv_date+6(2).
|
||||||
col_int = from_col_int + weekday.
|
CALL FUNCTION 'FIMA_X_DAY_IN_MONTH_COMPUTE'
|
||||||
col = zcl_excel_common=>convert_column2alpha( col_int ).
|
EXPORTING
|
||||||
|
i_datum = lv_date
|
||||||
value = day.
|
IMPORTING
|
||||||
CONDENSE value.
|
e_wochentag_nr = weekday.
|
||||||
|
|
||||||
c_worksheet->set_cell(
|
row = i_from_row + weekrow.
|
||||||
EXPORTING
|
col_int = from_col_int + weekday.
|
||||||
ip_column = col " Cell Column
|
col = zcl_excel_common=>convert_column2alpha( col_int ).
|
||||||
ip_row = row " Cell Row
|
|
||||||
ip_value = value " Cell Value
|
value = day.
|
||||||
ip_style = i_day_style " Single-Character Indicator
|
CONDENSE value.
|
||||||
).
|
|
||||||
|
c_worksheet->set_cell(
|
||||||
IF weekday = 7.
|
EXPORTING
|
||||||
" Add Calender Week
|
ip_column = col " Cell Column
|
||||||
zcl_helper=>add_calender_week(
|
ip_row = row " Cell Row
|
||||||
EXPORTING
|
ip_value = value " Cell Value
|
||||||
i_date = lv_date
|
ip_style = i_day_style " Single-Character Indicator
|
||||||
i_row = row
|
).
|
||||||
i_col = i_from_col
|
|
||||||
i_style = i_cw_style
|
IF weekday = 7.
|
||||||
CHANGING
|
" Add Calender Week
|
||||||
c_worksheet = c_worksheet
|
zcl_helper=>add_calender_week(
|
||||||
).
|
EXPORTING
|
||||||
weekrow = weekrow + 1.
|
i_date = lv_date
|
||||||
ENDIF.
|
i_row = row
|
||||||
lv_date = lv_date + 1.
|
i_col = i_from_col
|
||||||
ENDWHILE.
|
i_style = i_cw_style
|
||||||
" Add Calender Week
|
CHANGING
|
||||||
zcl_helper=>add_calender_week(
|
c_worksheet = c_worksheet
|
||||||
EXPORTING
|
).
|
||||||
i_date = lv_date
|
weekrow = weekrow + 1.
|
||||||
i_row = row
|
ENDIF.
|
||||||
i_col = i_from_col
|
lv_date = lv_date + 1.
|
||||||
i_style = i_cw_style
|
ENDWHILE.
|
||||||
CHANGING
|
" Add Calender Week
|
||||||
c_worksheet = c_worksheet
|
zcl_helper=>add_calender_week(
|
||||||
).
|
EXPORTING
|
||||||
" Add Created with abap2xlsx
|
i_date = lv_date
|
||||||
row = row + 2.
|
i_row = row
|
||||||
value = 'Created with abap2xlsx. Find more information at http://abap2xlsx.org.'(002).
|
i_col = i_from_col
|
||||||
hyperlink = zcl_excel_hyperlink=>create_external_link( 'http://abap2xlsx.org' ). "#EC NOTEXT
|
i_style = i_cw_style
|
||||||
c_worksheet->set_cell(
|
CHANGING
|
||||||
EXPORTING
|
c_worksheet = c_worksheet
|
||||||
ip_column = i_from_col " Cell Column
|
).
|
||||||
ip_row = row " Cell Row
|
" Add Created with abap2xlsx
|
||||||
ip_value = value " Cell Value
|
row = row + 2.
|
||||||
ip_hyperlink = hyperlink
|
value = 'Created with abap2xlsx. Find more information at http://abap2xlsx.org.'(002).
|
||||||
).
|
hyperlink = zcl_excel_hyperlink=>create_external_link( 'http://abap2xlsx.org' ). "#EC NOTEXT
|
||||||
col_int = from_col_int.
|
c_worksheet->set_cell(
|
||||||
WHILE col_int <= from_col_int + 7.
|
EXPORTING
|
||||||
col = zcl_excel_common=>convert_column2alpha( col_int ).
|
ip_column = i_from_col " Cell Column
|
||||||
IF sy-index = 1.
|
ip_row = row " Cell Row
|
||||||
width = '5.0'.
|
ip_value = value " Cell Value
|
||||||
ELSE.
|
ip_hyperlink = hyperlink
|
||||||
width = '11.4'.
|
).
|
||||||
ENDIF.
|
col_int = from_col_int.
|
||||||
|
col_max = from_col_int + 7.
|
||||||
c_worksheet->get_column_dimension( col )->set_width( width ).
|
WHILE col_int <= col_max.
|
||||||
col_int = col_int + 1.
|
col = zcl_excel_common=>convert_column2alpha( col_int ).
|
||||||
ENDWHILE.
|
IF sy-index = 1.
|
||||||
row = i_from_row + 1.
|
width = '5.0'.
|
||||||
WHILE row <= i_from_row + 6.
|
ELSE.
|
||||||
height = 50.
|
width = '11.4'.
|
||||||
c_worksheet->get_row_dimension( row )->set_row_height( height ).
|
ENDIF.
|
||||||
row = row + 1.
|
lr_col_dim = c_worksheet->get_column_dimension( col ).
|
||||||
ENDWHILE.
|
lr_col_dim->set_width( width ).
|
||||||
ENDMETHOD. "add_calendar
|
col_int = col_int + 1.
|
||||||
|
ENDWHILE.
|
||||||
METHOD add_calender_week.
|
row = i_from_row + 1.
|
||||||
DATA: week TYPE kweek,
|
row_max = i_from_row + 6.
|
||||||
week_int TYPE i,
|
WHILE row <= row_max.
|
||||||
value TYPE string.
|
height = 50.
|
||||||
" Add Calender Week
|
lr_row_dim = c_worksheet->get_row_dimension( row ).
|
||||||
CALL FUNCTION 'DATE_GET_WEEK'
|
lr_row_dim->set_row_height( height ).
|
||||||
EXPORTING
|
row = row + 1.
|
||||||
date = i_date " Date for which the week should be calculated
|
ENDWHILE.
|
||||||
IMPORTING
|
ENDMETHOD. "add_calendar
|
||||||
week = week. " Week for date (format:YYYYWW)
|
|
||||||
value = week+4(2).
|
METHOD add_calender_week.
|
||||||
week_int = value.
|
DATA: week TYPE kweek,
|
||||||
value = week_int.
|
week_int TYPE i,
|
||||||
CONDENSE value.
|
value TYPE string.
|
||||||
c_worksheet->set_cell(
|
" Add Calender Week
|
||||||
EXPORTING
|
CALL FUNCTION 'DATE_GET_WEEK'
|
||||||
ip_column = i_col " Cell Column
|
EXPORTING
|
||||||
ip_row = i_row " Cell Row
|
date = i_date " Date for which the week should be calculated
|
||||||
ip_value = value " Cell Value
|
IMPORTING
|
||||||
ip_style = i_style
|
week = week. " Week for date (format:YYYYWW)
|
||||||
).
|
value = week+4(2).
|
||||||
ENDMETHOD. "add_calender_week
|
week_int = value.
|
||||||
ENDCLASS. "zcl_helper IMPLEMENTATION</source>
|
value = week_int.
|
||||||
</PROG>
|
CONDENSE value.
|
||||||
|
c_worksheet->set_cell(
|
||||||
|
EXPORTING
|
||||||
|
ip_column = i_col " Cell Column
|
||||||
|
ip_row = i_row " Cell Row
|
||||||
|
ip_value = value " Cell Value
|
||||||
|
ip_style = i_style
|
||||||
|
).
|
||||||
|
ENDMETHOD. "add_calender_week
|
||||||
|
ENDCLASS. "zcl_helper IMPLEMENTATION</source>
|
||||||
|
</PROG>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user