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:
Gregor Wolf 2012-07-01 10:44:33 +00:00
parent cd1b8f99e6
commit 2d5fb26d4e
2 changed files with 723 additions and 707 deletions

View File

@ -1,359 +1,365 @@
<?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">
<textPool>
<language SPRAS="D">
<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="R" ENTRY="abap2xlsx Demo: Erzeugen eines Kalenders mit Bildern" LENGTH="70 "/>
</language>
<language SPRAS="E">
<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="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_PATH" ENTRY="D ." LENGTH="9 "/>
<textElement ID="S" KEY="P_TO" ENTRY="D ." LENGTH="9 "/>
</language>
</textPool>
<source>*&amp;---------------------------------------------------------------------*
*&amp; Report ZDEMO_CALENDAR
*&amp; abap2xlsx Demo: Create Calendar with Pictures
*&amp;---------------------------------------------------------------------*
*&amp; This report creates a monthly calendar in the specified date range.
*&amp; Each month is put on a seperate worksheet. The pictures for each
*&amp; month can be specified in a tab delimited file called &quot;Calendar.txt&quot;
*&amp; which is saved in the Export Directory. By default this is the SAP
*&amp; Workdir. The file contains 3 fields:
*&amp;
*&amp; Month (with leading 0)
*&amp; Image Filename
*&amp; Image Description
*&amp;
*&amp; The Images should be landscape JPEG&apos;s with a 3:2 ratio and min.
*&amp; 450 pixel height. They must also be saved in the Export Directory.
*&amp; In my tests I&apos;ve discovered a limit of 20 MB in the
*&amp; cl_gui_frontend_services=&gt;gui_download method. So keep your images
*&amp; smaller or chnage to a server export using OPEN DATASET.
*&amp;---------------------------------------------------------------------*
REPORT zdemo_calendar.
TYPE-POOLS: abap.
INCLUDE zdemo_calendar_classes.
DATA: lv_workdir TYPE string.
PARAMETERS: p_path TYPE zexcel_export_dir.
PARAMETERS: p_from TYPE demo_cr_date_from DEFAULT &apos;20120101&apos;,
p_to TYPE demo_cr_date_to DEFAULT &apos;20121231&apos;.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
lv_workdir = p_path.
cl_gui_frontend_services=&gt;directory_browse( EXPORTING initial_folder = lv_workdir
CHANGING selected_folder = lv_workdir ).
p_path = lv_workdir.
INITIALIZATION.
cl_gui_frontend_services=&gt;get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ).
cl_gui_cfw=&gt;flush( ).
p_path = lv_workdir.
START-OF-SELECTION.
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_drawing TYPE REF TO zcl_excel_drawing.
DATA: lo_style_month TYPE REF TO zcl_excel_style,
lv_style_month_guid TYPE zexcel_cell_style.
DATA: lo_style_border TYPE REF TO zcl_excel_style,
lo_border_dark TYPE REF TO zcl_excel_style_border,
lv_style_border_guid TYPE zexcel_cell_style.
DATA: lo_style_center TYPE REF TO zcl_excel_style,
lv_style_center_guid TYPE zexcel_cell_style.
DATA: lv_file TYPE xstring,
lv_bytecount TYPE i,
lt_file_tab TYPE solix_tab.
DATA: lv_full_path TYPE string,
image_descr_path TYPE string,
lv_file_separator TYPE c.
DATA: lv_content TYPE xstring,
width TYPE i.
DATA: month TYPE i,
month_nr TYPE fcmnr,
count TYPE i VALUE 1,
title TYPE zexcel_sheet_title,
value TYPE string,
image_path TYPE string,
date_from TYPE datum,
date_to TYPE datum,
row TYPE zexcel_cell_row,
to_col TYPE zexcel_cell_column_alpha,
to_col_int TYPE i.
DATA: month_names TYPE TABLE OF t247.
FIELD-SYMBOLS: &lt;month_name&gt; LIKE LINE OF month_names.
TYPES: BEGIN OF tt_datatab,
month_nr TYPE fcmnr,
filename TYPE string,
descr TYPE string,
END OF tt_datatab.
DATA: image_descriptions TYPE TABLE OF tt_datatab.
FIELD-SYMBOLS: &lt;img_descr&gt; LIKE LINE OF image_descriptions.
CONSTANTS: lv_default_file_name TYPE string VALUE &apos;Calendar&apos;, &quot;#EC NOTEXT
from_row TYPE zexcel_cell_row VALUE 28,
from_col TYPE zexcel_cell_column_alpha VALUE &apos;C&apos;,
c_height TYPE i VALUE 450, &quot; Image Height
c_factor TYPE f VALUE &apos;1.5&apos;. &quot; Image Ratio, default 3:2
IF p_path IS INITIAL.
p_path = lv_workdir.
ENDIF.
cl_gui_frontend_services=&gt;get_file_separator( CHANGING file_separator = lv_file_separator ).
CONCATENATE p_path lv_file_separator lv_default_file_name &apos;.xlsx&apos; INTO lv_full_path. &quot;#EC NOTEXT
&quot; Read Image Names for Month and Description
CONCATENATE p_path lv_file_separator lv_default_file_name &apos;.txt&apos; INTO image_descr_path. &quot;#EC NOTEXT
cl_gui_frontend_services=&gt;gui_upload(
EXPORTING
filename = image_descr_path &quot; Name of file
filetype = &apos;ASC&apos; &quot; File Type (ASCII, Binary)
has_field_separator = &apos;X&apos;
read_by_line = &apos;X&apos; &quot; File Written Line-By-Line to the Internal Table
CHANGING
data_tab = image_descriptions &quot; Transfer table for file contents
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19
).
IF sy-subrc &lt;&gt; 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
&quot; Creates active sheet
CREATE OBJECT lo_excel.
&quot; Create Styles
&quot; Create an underline double style
lo_style_month = lo_excel-&gt;add_new_style( ).
&quot; lo_style_month-&gt;font-&gt;underline = abap_true.
&quot; lo_style_month-&gt;font-&gt;underline_mode = zcl_excel_style_font=&gt;c_underline_single.
lo_style_month-&gt;font-&gt;name = zcl_excel_style_font=&gt;c_name_roman.
lo_style_month-&gt;font-&gt;scheme = zcl_excel_style_font=&gt;c_scheme_none.
lo_style_month-&gt;font-&gt;family = zcl_excel_style_font=&gt;c_family_roman.
lo_style_month-&gt;font-&gt;bold = abap_true.
lo_style_month-&gt;font-&gt;size = 36.
lv_style_month_guid = lo_style_month-&gt;get_guid( ).
&quot; Create border object
CREATE OBJECT lo_border_dark.
lo_border_dark-&gt;border_color-rgb = zcl_excel_style_color=&gt;c_black.
lo_border_dark-&gt;border_style = zcl_excel_style_border=&gt;c_border_thin.
&quot;Create style with border
lo_style_border = lo_excel-&gt;add_new_style( ).
lo_style_border-&gt;borders-&gt;allborders = lo_border_dark.
lo_style_border-&gt;alignment-&gt;horizontal = zcl_excel_style_alignment=&gt;c_horizontal_right.
lo_style_border-&gt;alignment-&gt;vertical = zcl_excel_style_alignment=&gt;c_vertical_top.
lv_style_border_guid = lo_style_border-&gt;get_guid( ).
&quot;Create style alignment center
lo_style_center = lo_excel-&gt;add_new_style( ).
lo_style_center-&gt;alignment-&gt;horizontal = zcl_excel_style_alignment=&gt;c_horizontal_center.
lo_style_center-&gt;alignment-&gt;vertical = zcl_excel_style_alignment=&gt;c_vertical_top.
lv_style_center_guid = lo_style_center-&gt;get_guid( ).
&quot; Get Month Names
CALL FUNCTION &apos;MONTH_NAMES_GET&apos;
TABLES
month_names = month_names.
zcl_date_calculation=&gt;months_between_two_dates(
EXPORTING
i_date_from = p_from
i_date_to = p_to
i_incl_to = abap_true
IMPORTING
e_month = month
).
date_from = p_from.
WHILE count &lt;= month.
IF count = 1.
&quot; Get active sheet
lo_worksheet = lo_excel-&gt;get_active_worksheet( ).
ELSE.
lo_worksheet = lo_excel-&gt;add_new_worksheet( ).
ENDIF.
lo_worksheet-&gt;zif_excel_sheet_properties~selected = zif_excel_sheet_properties=&gt;c_selected.
title = count.
value = count.
CONDENSE title.
CONDENSE value.
lo_worksheet-&gt;set_title( title ).
lo_worksheet-&gt;set_print_gridlines( abap_false ).
lo_worksheet-&gt;sheet_setup-&gt;paper_size = zcl_excel_sheet_setup=&gt;c_papersize_a4.
lo_worksheet-&gt;sheet_setup-&gt;margin_top = &apos;0.80&apos;.
lo_worksheet-&gt;sheet_setup-&gt;margin_left = &apos;0.55&apos;.
lo_worksheet-&gt;sheet_setup-&gt;margin_right = &apos;0.05&apos;.
lo_worksheet-&gt;sheet_setup-&gt;margin_bottom = &apos;0.30&apos;.
lo_worksheet-&gt;get_column_dimension( &apos;A&apos; )-&gt;set_width( &apos;1.0&apos; ).
lo_worksheet-&gt;get_column_dimension( &apos;B&apos; )-&gt;set_width( &apos;2.0&apos; ).
lo_worksheet-&gt;get_column_dimension( &apos;K&apos; )-&gt;set_width( &apos;3.0&apos; ).
lo_worksheet-&gt;sheet_setup-&gt;horizontal_centered = abap_true.
&quot; Add Month Name
month_nr = date_from+4(2).
READ TABLE month_names WITH KEY mnr = month_nr ASSIGNING &lt;month_name&gt;.
CONCATENATE &lt;month_name&gt;-ltx ` ` date_from(4) INTO value.
row = from_row - 2.
lo_worksheet-&gt;set_cell(
EXPORTING
ip_column = from_col &quot; Cell Column
ip_row = row &quot; Cell Row
ip_value = value &quot; Cell Value
ip_style = lv_style_month_guid
).
to_col_int = zcl_excel_common=&gt;convert_column2int( from_col ).
to_col = zcl_excel_common=&gt;convert_column2alpha( to_col_int + 7 ).
lo_worksheet-&gt;set_merge(
EXPORTING
ip_column_start = from_col &quot; Cell Column Start
ip_column_end = to_col &quot; Cell Column End
ip_row = row &quot; Cell Row
ip_row_to = row &quot; Cell Row
).
&quot; Add drawing from a XSTRING read from a file
UNASSIGN &lt;img_descr&gt;.
READ TABLE image_descriptions WITH KEY month_nr = month_nr ASSIGNING &lt;img_descr&gt;.
IF &lt;img_descr&gt; IS ASSIGNED.
value = &lt;img_descr&gt;-descr.
row = from_row - 4.
lo_worksheet-&gt;set_cell(
EXPORTING
ip_column = from_col &quot; Cell Column
ip_row = row &quot; Cell Row
ip_value = value &quot; Cell Value
).
lo_worksheet-&gt;get_row_dimension( row )-&gt;set_row_height( &apos;18.0&apos; ).
CONCATENATE p_path lv_file_separator &lt;img_descr&gt;-filename INTO image_path.
lo_drawing = lo_excel-&gt;add_new_drawing( ).
lo_drawing-&gt;set_position( ip_from_row = 1
ip_from_col = &apos;B&apos; ).
lv_content = zcl_helper=&gt;load_image( image_path ).
width = c_height * c_factor.
lo_drawing-&gt;set_media( ip_media = lv_content
ip_media_type = &apos;jpg&apos;
ip_width = width
ip_height = c_height ).
lo_worksheet-&gt;add_drawing( lo_drawing ).
ENDIF.
&quot; Add Calendar
CALL FUNCTION &apos;SLS_MISC_GET_LAST_DAY_OF_MONTH&apos;
EXPORTING
day_in = date_from
IMPORTING
last_day_of_month = date_to.
zcl_helper=&gt;add_calendar(
EXPORTING
i_date_from = date_from
i_date_to = date_to
i_from_row = from_row
i_from_col = from_col
i_day_style = lv_style_border_guid
i_cw_style = lv_style_center_guid
CHANGING
c_worksheet = lo_worksheet
).
count = count + 1.
date_from = date_to + 1.
ENDWHILE.
lo_excel-&gt;set_active_sheet_index_by_name( &apos;1&apos; ).
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
lv_file = lo_excel_writer-&gt;write_file( lo_excel ).
&quot; Convert to binary
CALL FUNCTION &apos;SCMS_XSTRING_TO_BINARY&apos;
EXPORTING
buffer = lv_file
IMPORTING
output_length = lv_bytecount
TABLES
binary_tab = lt_file_tab.
* &quot; This method is only available on AS ABAP &gt; 6.40
* lt_file_tab = cl_bcs_convert=&gt;xstring_to_solix( iv_xstring = lv_file ).
* lv_bytecount = xstrlen( lv_file ).
&quot; Save the file
cl_gui_frontend_services=&gt;gui_download(
EXPORTING bin_filesize = lv_bytecount
filename = lv_full_path
filetype = &apos;BIN&apos;
CHANGING data_tab = lt_file_tab
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24
).
IF sy-subrc &lt;&gt; 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.</source>
</PROG>
<?xml version="1.0" encoding="utf-16"?>
<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>
<language SPRAS="D">
<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="R" ENTRY="abap2xlsx Demo: Erzeugen eines Kalenders mit Bildern" LENGTH="70 "/>
</language>
<language SPRAS="E">
<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="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_PATH" ENTRY="D ." LENGTH="9 "/>
<textElement ID="S" KEY="P_TO" ENTRY="D ." LENGTH="9 "/>
</language>
</textPool>
<source>*&amp;---------------------------------------------------------------------*
*&amp; Report ZDEMO_CALENDAR
*&amp; abap2xlsx Demo: Create Calendar with Pictures
*&amp;---------------------------------------------------------------------*
*&amp; This report creates a monthly calendar in the specified date range.
*&amp; Each month is put on a seperate worksheet. The pictures for each
*&amp; month can be specified in a tab delimited file called &quot;Calendar.txt&quot;
*&amp; which is saved in the Export Directory. By default this is the SAP
*&amp; Workdir. The file contains 3 fields:
*&amp;
*&amp; Month (with leading 0)
*&amp; Image Filename
*&amp; Image Description
*&amp;
*&amp; The Images should be landscape JPEG&apos;s with a 3:2 ratio and min.
*&amp; 450 pixel height. They must also be saved in the Export Directory.
*&amp; In my tests I&apos;ve discovered a limit of 20 MB in the
*&amp; cl_gui_frontend_services=&gt;gui_download method. So keep your images
*&amp; smaller or chnage to a server export using OPEN DATASET.
*&amp;---------------------------------------------------------------------*
REPORT zdemo_calendar.
TYPE-POOLS: abap.
INCLUDE zdemo_calendar_classes.
DATA: lv_workdir TYPE string.
PARAMETERS: p_path TYPE zexcel_export_dir.
PARAMETERS: p_from TYPE dfrom DEFAULT &apos;20120101&apos;,
p_to TYPE dto DEFAULT &apos;20121231&apos;.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
lv_workdir = p_path.
cl_gui_frontend_services=&gt;directory_browse( EXPORTING initial_folder = lv_workdir
CHANGING selected_folder = lv_workdir ).
p_path = lv_workdir.
INITIALIZATION.
cl_gui_frontend_services=&gt;get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ).
cl_gui_cfw=&gt;flush( ).
p_path = lv_workdir.
START-OF-SELECTION.
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_col_dim TYPE REF TO zcl_excel_worksheet_columndime,
lo_row_dim TYPE REF TO ZCL_EXCEL_WORKSHEET_ROWDIMENSI,
lo_drawing TYPE REF TO zcl_excel_drawing.
DATA: lo_style_month TYPE REF TO zcl_excel_style,
lv_style_month_guid TYPE zexcel_cell_style.
DATA: lo_style_border TYPE REF TO zcl_excel_style,
lo_border_dark TYPE REF TO zcl_excel_style_border,
lv_style_border_guid TYPE zexcel_cell_style.
DATA: lo_style_center TYPE REF TO zcl_excel_style,
lv_style_center_guid TYPE zexcel_cell_style.
DATA: lv_file TYPE xstring,
lv_bytecount TYPE i,
lt_file_tab TYPE solix_tab.
DATA: lv_full_path TYPE string,
image_descr_path TYPE string,
lv_file_separator TYPE c.
DATA: lv_content TYPE xstring,
width TYPE i.
DATA: month TYPE i,
month_nr TYPE fcmnr,
count TYPE i VALUE 1,
title TYPE zexcel_sheet_title,
value TYPE string,
image_path TYPE string,
date_from TYPE datum,
date_to TYPE datum,
row TYPE zexcel_cell_row,
to_col TYPE zexcel_cell_column_alpha,
to_col_int TYPE i.
DATA: month_names TYPE TABLE OF t247.
FIELD-SYMBOLS: &lt;month_name&gt; LIKE LINE OF month_names.
TYPES: BEGIN OF tt_datatab,
month_nr TYPE fcmnr,
filename TYPE string,
descr TYPE string,
END OF tt_datatab.
DATA: image_descriptions TYPE TABLE OF tt_datatab.
FIELD-SYMBOLS: &lt;img_descr&gt; LIKE LINE OF image_descriptions.
CONSTANTS: lv_default_file_name TYPE string VALUE &apos;Calendar&apos;, &quot;#EC NOTEXT
from_row TYPE zexcel_cell_row VALUE 28,
from_col TYPE zexcel_cell_column_alpha VALUE &apos;C&apos;,
c_height TYPE i VALUE 450, &quot; Image Height
c_factor TYPE f VALUE &apos;1.5&apos;. &quot; Image Ratio, default 3:2
IF p_path IS INITIAL.
p_path = lv_workdir.
ENDIF.
cl_gui_frontend_services=&gt;get_file_separator( CHANGING file_separator = lv_file_separator ).
CONCATENATE p_path lv_file_separator lv_default_file_name &apos;.xlsx&apos; INTO lv_full_path. &quot;#EC NOTEXT
&quot; Read Image Names for Month and Description
CONCATENATE p_path lv_file_separator lv_default_file_name &apos;.txt&apos; INTO image_descr_path. &quot;#EC NOTEXT
cl_gui_frontend_services=&gt;gui_upload(
EXPORTING
filename = image_descr_path &quot; Name of file
filetype = &apos;ASC&apos; &quot; File Type (ASCII, Binary)
has_field_separator = &apos;X&apos;
read_by_line = &apos;X&apos; &quot; File Written Line-By-Line to the Internal Table
CHANGING
data_tab = image_descriptions &quot; Transfer table for file contents
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19
).
IF sy-subrc &lt;&gt; 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
&quot; Creates active sheet
CREATE OBJECT lo_excel.
&quot; Create Styles
&quot; Create an underline double style
lo_style_month = lo_excel-&gt;add_new_style( ).
&quot; lo_style_month-&gt;font-&gt;underline = abap_true.
&quot; lo_style_month-&gt;font-&gt;underline_mode = zcl_excel_style_font=&gt;c_underline_single.
lo_style_month-&gt;font-&gt;name = zcl_excel_style_font=&gt;c_name_roman.
lo_style_month-&gt;font-&gt;scheme = zcl_excel_style_font=&gt;c_scheme_none.
lo_style_month-&gt;font-&gt;family = zcl_excel_style_font=&gt;c_family_roman.
lo_style_month-&gt;font-&gt;bold = abap_true.
lo_style_month-&gt;font-&gt;size = 36.
lv_style_month_guid = lo_style_month-&gt;get_guid( ).
&quot; Create border object
CREATE OBJECT lo_border_dark.
lo_border_dark-&gt;border_color-rgb = zcl_excel_style_color=&gt;c_black.
lo_border_dark-&gt;border_style = zcl_excel_style_border=&gt;c_border_thin.
&quot;Create style with border
lo_style_border = lo_excel-&gt;add_new_style( ).
lo_style_border-&gt;borders-&gt;allborders = lo_border_dark.
lo_style_border-&gt;alignment-&gt;horizontal = zcl_excel_style_alignment=&gt;c_horizontal_right.
lo_style_border-&gt;alignment-&gt;vertical = zcl_excel_style_alignment=&gt;c_vertical_top.
lv_style_border_guid = lo_style_border-&gt;get_guid( ).
&quot;Create style alignment center
lo_style_center = lo_excel-&gt;add_new_style( ).
lo_style_center-&gt;alignment-&gt;horizontal = zcl_excel_style_alignment=&gt;c_horizontal_center.
lo_style_center-&gt;alignment-&gt;vertical = zcl_excel_style_alignment=&gt;c_vertical_top.
lv_style_center_guid = lo_style_center-&gt;get_guid( ).
&quot; Get Month Names
CALL FUNCTION &apos;MONTH_NAMES_GET&apos;
TABLES
month_names = month_names.
zcl_date_calculation=&gt;months_between_two_dates(
EXPORTING
i_date_from = p_from
i_date_to = p_to
i_incl_to = abap_true
IMPORTING
e_month = month
).
date_from = p_from.
WHILE count &lt;= month.
IF count = 1.
&quot; Get active sheet
lo_worksheet = lo_excel-&gt;get_active_worksheet( ).
ELSE.
lo_worksheet = lo_excel-&gt;add_new_worksheet( ).
ENDIF.
lo_worksheet-&gt;zif_excel_sheet_properties~selected = zif_excel_sheet_properties=&gt;c_selected.
title = count.
value = count.
CONDENSE title.
CONDENSE value.
lo_worksheet-&gt;set_title( title ).
lo_worksheet-&gt;set_print_gridlines( abap_false ).
lo_worksheet-&gt;sheet_setup-&gt;paper_size = zcl_excel_sheet_setup=&gt;c_papersize_a4.
lo_worksheet-&gt;sheet_setup-&gt;margin_top = &apos;0.80&apos;.
lo_worksheet-&gt;sheet_setup-&gt;margin_left = &apos;0.55&apos;.
lo_worksheet-&gt;sheet_setup-&gt;margin_right = &apos;0.05&apos;.
lo_worksheet-&gt;sheet_setup-&gt;margin_bottom = &apos;0.30&apos;.
lo_col_dim = lo_worksheet-&gt;get_column_dimension( &apos;A&apos; ).
lo_col_dim-&gt;set_width( &apos;1.0&apos; ).
lo_col_dim = lo_worksheet-&gt;get_column_dimension( &apos;B&apos; ).
lo_col_dim-&gt;set_width( &apos;2.0&apos; ).
lo_col_dim = lo_worksheet-&gt;get_column_dimension( &apos;K&apos; ).
lo_col_dim-&gt;set_width( &apos;3.0&apos; ).
lo_worksheet-&gt;sheet_setup-&gt;horizontal_centered = abap_true.
&quot; Add Month Name
month_nr = date_from+4(2).
READ TABLE month_names WITH KEY mnr = month_nr ASSIGNING &lt;month_name&gt;.
CONCATENATE &lt;month_name&gt;-ltx ` ` date_from(4) INTO value.
row = from_row - 2.
lo_worksheet-&gt;set_cell(
EXPORTING
ip_column = from_col &quot; Cell Column
ip_row = row &quot; Cell Row
ip_value = value &quot; Cell Value
ip_style = lv_style_month_guid
).
to_col_int = zcl_excel_common=&gt;convert_column2int( from_col ) + 7.
to_col = zcl_excel_common=&gt;convert_column2alpha( to_col_int ).
lo_worksheet-&gt;set_merge(
EXPORTING
ip_column_start = from_col &quot; Cell Column Start
ip_column_end = to_col &quot; Cell Column End
ip_row = row &quot; Cell Row
ip_row_to = row &quot; Cell Row
).
&quot; Add drawing from a XSTRING read from a file
UNASSIGN &lt;img_descr&gt;.
READ TABLE image_descriptions WITH KEY month_nr = month_nr ASSIGNING &lt;img_descr&gt;.
IF &lt;img_descr&gt; IS ASSIGNED.
value = &lt;img_descr&gt;-descr.
row = from_row - 3.
lo_worksheet-&gt;set_cell(
EXPORTING
ip_column = from_col &quot; Cell Column
ip_row = row &quot; Cell Row
ip_value = value &quot; Cell Value
).
lo_row_dim = lo_worksheet-&gt;get_row_dimension( row ).
lo_row_dim-&gt;set_row_height( &apos;22.0&apos; ).
CONCATENATE p_path lv_file_separator &lt;img_descr&gt;-filename INTO image_path.
lo_drawing = lo_excel-&gt;add_new_drawing( ).
lo_drawing-&gt;set_position( ip_from_row = 1
ip_from_col = &apos;B&apos; ).
lv_content = zcl_helper=&gt;load_image( image_path ).
width = c_height * c_factor.
lo_drawing-&gt;set_media( ip_media = lv_content
ip_media_type = &apos;jpg&apos;
ip_width = width
ip_height = c_height ).
lo_worksheet-&gt;add_drawing( lo_drawing ).
ENDIF.
&quot; Add Calendar
CALL FUNCTION &apos;SLS_MISC_GET_LAST_DAY_OF_MONTH&apos;
EXPORTING
day_in = date_from
IMPORTING
last_day_of_month = date_to.
zcl_helper=&gt;add_calendar(
EXPORTING
i_date_from = date_from
i_date_to = date_to
i_from_row = from_row
i_from_col = from_col
i_day_style = lv_style_border_guid
i_cw_style = lv_style_center_guid
CHANGING
c_worksheet = lo_worksheet
).
count = count + 1.
date_from = date_to + 1.
ENDWHILE.
lo_excel-&gt;set_active_sheet_index_by_name( &apos;1&apos; ).
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
lv_file = lo_excel_writer-&gt;write_file( lo_excel ).
&quot; Convert to binary
CALL FUNCTION &apos;SCMS_XSTRING_TO_BINARY&apos;
EXPORTING
buffer = lv_file
IMPORTING
output_length = lv_bytecount
TABLES
binary_tab = lt_file_tab.
* &quot; This method is only available on AS ABAP &gt; 6.40
* lt_file_tab = cl_bcs_convert=&gt;xstring_to_solix( iv_xstring = lv_file ).
* lv_bytecount = xstrlen( lv_file ).
&quot; Save the file
cl_gui_frontend_services=&gt;gui_download(
EXPORTING bin_filesize = lv_bytecount
filename = lv_full_path
filetype = &apos;BIN&apos;
CHANGING data_tab = lt_file_tab
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24
).
IF sy-subrc &lt;&gt; 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.</source>
</PROG>

View File

@ -1,348 +1,358 @@
<?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">
<textPool>
<language SPRAS="E">
<textElement ID="R" ENTRY="Include ZDEMO_CALENDAR_CLASSES" LENGTH="30 "/>
</language>
</textPool>
<source>*&amp;---------------------------------------------------------------------*
*&amp; Include ZDEMO_CALENDAR_CLASSES
*&amp;---------------------------------------------------------------------*
*&amp;---------------------------------------------------------------------*
*&amp; Class ZCL_DATE_CALCULATION
*&amp;---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
CLASS zcl_date_calculation DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: months_between_two_dates
IMPORTING
i_date_from TYPE datum
i_date_to TYPE datum
i_incl_to TYPE flag
EXPORTING
e_month TYPE i.
ENDCLASS. &quot;ZCL_DATE_CALCULATION
*----------------------------------------------------------------------*
* CLASS ZCL_DATE_CALCULATION IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zcl_date_calculation IMPLEMENTATION.
METHOD months_between_two_dates.
DATA: date_to TYPE datum.
DATA: BEGIN OF datum_von,
jjjj(4) TYPE n,
mm(2) TYPE n,
tt(2) TYPE n,
END OF datum_von.
DATA: BEGIN OF datum_bis,
jjjj(4) TYPE n,
mm(2) TYPE n,
tt(2) TYPE n,
END OF datum_bis.
e_month = 0.
CHECK NOT ( i_date_from IS INITIAL )
AND NOT ( i_date_to IS INITIAL ).
date_to = i_date_to.
IF i_incl_to = abap_true.
date_to = date_to + 1.
ENDIF.
datum_von = i_date_from.
datum_bis = date_to.
e_month = ( datum_bis-jjjj - datum_von-jjjj ) * 12
+ ( datum_bis-mm - datum_von-mm ).
ENDMETHOD. &quot;MONTHS_BETWEEN_TWO_DATES
ENDCLASS. &quot;ZCL_DATE_CALCULATION IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS zcl_date_calculation_test DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zcl_date_calculation_test DEFINITION FOR TESTING
RISK LEVEL HARMLESS
DURATION SHORT.
PUBLIC SECTION.
METHODS:
months_between_two_dates FOR TESTING.
ENDCLASS. &quot;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 &apos;20120101&apos;,
date_to TYPE datum VALUE &apos;20121231&apos;.
DATA: month TYPE i.
zcl_date_calculation=&gt;months_between_two_dates(
EXPORTING
i_date_from = date_from
i_date_to = date_to
i_incl_to = abap_true
IMPORTING
e_month = month
).
cl_aunit_assert=&gt;assert_equals(
exp = 12 &quot; Data Object with Expected Type
act = month &quot; Data Object with Current Value
msg = &apos;Calculated date is wrong&apos; &quot; Message in Case of Error
).
ENDMETHOD. &quot;months_between_two_dates
ENDCLASS. &quot;zcl_date_calculation_test IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS zcl_helper DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zcl_helper DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
load_image
IMPORTING
filename TYPE string
RETURNING value(r_image) TYPE xstring,
add_calendar
IMPORTING
i_date_from TYPE datum
i_date_to TYPE datum
i_from_row TYPE zexcel_cell_row
i_from_col TYPE zexcel_cell_column_alpha
i_day_style TYPE zexcel_cell_style
i_cw_style TYPE zexcel_cell_style
CHANGING
c_worksheet TYPE REF TO zcl_excel_worksheet,
add_calender_week
IMPORTING
i_date TYPE datum
i_row TYPE zexcel_cell_row
i_col TYPE zexcel_cell_column_alpha
i_style TYPE zexcel_cell_style
CHANGING
c_worksheet TYPE REF TO zcl_excel_worksheet.
ENDCLASS. &quot;zcl_helper DEFINITION
*----------------------------------------------------------------------*
* CLASS zcl_helper IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zcl_helper IMPLEMENTATION.
METHOD load_image.
&quot;Load samle image
DATA: lt_bin TYPE solix_tab,
lv_len TYPE i.
CALL METHOD cl_gui_frontend_services=&gt;gui_upload
EXPORTING
filename = filename
filetype = &apos;BIN&apos;
IMPORTING
filelength = lv_len
CHANGING
data_tab = lt_bin
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
IF sy-subrc &lt;&gt; 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION &apos;SCMS_BINARY_TO_XSTRING&apos;
EXPORTING
input_length = lv_len
IMPORTING
buffer = r_image
TABLES
binary_tab = lt_bin
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc &lt;&gt; 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDMETHOD. &quot;load_image
METHOD add_calendar.
DATA: row TYPE zexcel_cell_row,
col_int TYPE zexcel_cell_column,
from_col_int TYPE zexcel_cell_column,
col TYPE zexcel_cell_column_alpha.
DATA: lv_date TYPE datum,
value TYPE string,
weekday TYPE wotnr,
weekrow TYPE wotnr VALUE 1,
day TYPE i,
width TYPE f,
height TYPE f.
DATA: hyperlink TYPE REF TO zcl_excel_hyperlink.
DATA: day_names TYPE TABLE OF t246.
FIELD-SYMBOLS: &lt;day_name&gt; LIKE LINE OF day_names.
lv_date = i_date_from.
from_col_int = zcl_excel_common=&gt;convert_column2int( i_from_col ).
&quot; Add description for Calendar Week
c_worksheet-&gt;set_cell(
EXPORTING
ip_column = i_from_col &quot; Cell Column
ip_row = i_from_row &quot; Cell Row
ip_value = &apos;CW&apos;(001) &quot; Cell Value
ip_style = i_cw_style
).
&quot; Add Days
CALL FUNCTION &apos;DAY_NAMES_GET&apos;
TABLES
day_names = day_names.
LOOP AT day_names ASSIGNING &lt;day_name&gt;.
row = i_from_row.
col_int = from_col_int + &lt;day_name&gt;-wotnr.
col = zcl_excel_common=&gt;convert_column2alpha( col_int ).
value = &lt;day_name&gt;-langt.
c_worksheet-&gt;set_cell(
EXPORTING
ip_column = col &quot; Cell Column
ip_row = row &quot; Cell Row
ip_value = value &quot; Cell Value
ip_style = i_cw_style
).
ENDLOOP.
WHILE lv_date &lt;= i_date_to.
day = lv_date+6(2).
CALL FUNCTION &apos;FIMA_X_DAY_IN_MONTH_COMPUTE&apos;
EXPORTING
i_datum = lv_date
IMPORTING
e_wochentag_nr = weekday.
row = i_from_row + weekrow.
col_int = from_col_int + weekday.
col = zcl_excel_common=&gt;convert_column2alpha( col_int ).
value = day.
CONDENSE value.
c_worksheet-&gt;set_cell(
EXPORTING
ip_column = col &quot; Cell Column
ip_row = row &quot; Cell Row
ip_value = value &quot; Cell Value
ip_style = i_day_style &quot; Single-Character Indicator
).
IF weekday = 7.
&quot; Add Calender Week
zcl_helper=&gt;add_calender_week(
EXPORTING
i_date = lv_date
i_row = row
i_col = i_from_col
i_style = i_cw_style
CHANGING
c_worksheet = c_worksheet
).
weekrow = weekrow + 1.
ENDIF.
lv_date = lv_date + 1.
ENDWHILE.
&quot; Add Calender Week
zcl_helper=&gt;add_calender_week(
EXPORTING
i_date = lv_date
i_row = row
i_col = i_from_col
i_style = i_cw_style
CHANGING
c_worksheet = c_worksheet
).
&quot; Add Created with abap2xlsx
row = row + 2.
value = &apos;Created with abap2xlsx. Find more information at http://abap2xlsx.org.&apos;(002).
hyperlink = zcl_excel_hyperlink=&gt;create_external_link( &apos;http://abap2xlsx.org&apos; ). &quot;#EC NOTEXT
c_worksheet-&gt;set_cell(
EXPORTING
ip_column = i_from_col &quot; Cell Column
ip_row = row &quot; Cell Row
ip_value = value &quot; Cell Value
ip_hyperlink = hyperlink
).
col_int = from_col_int.
WHILE col_int &lt;= from_col_int + 7.
col = zcl_excel_common=&gt;convert_column2alpha( col_int ).
IF sy-index = 1.
width = &apos;5.0&apos;.
ELSE.
width = &apos;11.4&apos;.
ENDIF.
c_worksheet-&gt;get_column_dimension( col )-&gt;set_width( width ).
col_int = col_int + 1.
ENDWHILE.
row = i_from_row + 1.
WHILE row &lt;= i_from_row + 6.
height = 50.
c_worksheet-&gt;get_row_dimension( row )-&gt;set_row_height( height ).
row = row + 1.
ENDWHILE.
ENDMETHOD. &quot;add_calendar
METHOD add_calender_week.
DATA: week TYPE kweek,
week_int TYPE i,
value TYPE string.
&quot; Add Calender Week
CALL FUNCTION &apos;DATE_GET_WEEK&apos;
EXPORTING
date = i_date &quot; Date for which the week should be calculated
IMPORTING
week = week. &quot; Week for date (format:YYYYWW)
value = week+4(2).
week_int = value.
value = week_int.
CONDENSE value.
c_worksheet-&gt;set_cell(
EXPORTING
ip_column = i_col &quot; Cell Column
ip_row = i_row &quot; Cell Row
ip_value = value &quot; Cell Value
ip_style = i_style
).
ENDMETHOD. &quot;add_calender_week
ENDCLASS. &quot;zcl_helper IMPLEMENTATION</source>
</PROG>
<?xml version="1.0" encoding="utf-16"?>
<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>
<language SPRAS="E">
<textElement ID="R" ENTRY="Include ZDEMO_CALENDAR_CLASSES" LENGTH="30 "/>
</language>
</textPool>
<source>*&amp;---------------------------------------------------------------------*
*&amp; Include ZDEMO_CALENDAR_CLASSES
*&amp;---------------------------------------------------------------------*
*&amp;---------------------------------------------------------------------*
*&amp; Class ZCL_DATE_CALCULATION
*&amp;---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
CLASS zcl_date_calculation DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: months_between_two_dates
IMPORTING
i_date_from TYPE datum
i_date_to TYPE datum
i_incl_to TYPE flag
EXPORTING
e_month TYPE i.
ENDCLASS. &quot;ZCL_DATE_CALCULATION
*----------------------------------------------------------------------*
* CLASS ZCL_DATE_CALCULATION IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zcl_date_calculation IMPLEMENTATION.
METHOD months_between_two_dates.
DATA: date_to TYPE datum.
DATA: BEGIN OF datum_von,
jjjj(4) TYPE n,
mm(2) TYPE n,
tt(2) TYPE n,
END OF datum_von.
DATA: BEGIN OF datum_bis,
jjjj(4) TYPE n,
mm(2) TYPE n,
tt(2) TYPE n,
END OF datum_bis.
e_month = 0.
CHECK NOT ( i_date_from IS INITIAL )
AND NOT ( i_date_to IS INITIAL ).
date_to = i_date_to.
IF i_incl_to = abap_true.
date_to = date_to + 1.
ENDIF.
datum_von = i_date_from.
datum_bis = date_to.
e_month = ( datum_bis-jjjj - datum_von-jjjj ) * 12
+ ( datum_bis-mm - datum_von-mm ).
ENDMETHOD. &quot;MONTHS_BETWEEN_TWO_DATES
ENDCLASS. &quot;ZCL_DATE_CALCULATION IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS zcl_date_calculation_test DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zcl_date_calculation_test DEFINITION FOR TESTING
&quot; DURATION SHORT
&quot; RISK LEVEL HARMLESS
&quot;#AU Duration Medium
&quot;#AU Risk_Level Harmless
.
PUBLIC SECTION.
METHODS:
months_between_two_dates FOR TESTING.
ENDCLASS. &quot;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 &apos;20120101&apos;,
date_to TYPE datum VALUE &apos;20121231&apos;.
DATA: month TYPE i.
zcl_date_calculation=&gt;months_between_two_dates(
EXPORTING
i_date_from = date_from
i_date_to = date_to
i_incl_to = abap_true
IMPORTING
e_month = month
).
cl_aunit_assert=&gt;assert_equals(
exp = 12 &quot; Data Object with Expected Type
act = month &quot; Data Object with Current Value
msg = &apos;Calculated date is wrong&apos; &quot; Message in Case of Error
).
ENDMETHOD. &quot;months_between_two_dates
ENDCLASS. &quot;zcl_date_calculation_test IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS zcl_helper DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zcl_helper DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
load_image
IMPORTING
filename TYPE string
RETURNING value(r_image) TYPE xstring,
add_calendar
IMPORTING
i_date_from TYPE datum
i_date_to TYPE datum
i_from_row TYPE zexcel_cell_row
i_from_col TYPE zexcel_cell_column_alpha
i_day_style TYPE zexcel_cell_style
i_cw_style TYPE zexcel_cell_style
CHANGING
c_worksheet TYPE REF TO zcl_excel_worksheet,
add_calender_week
IMPORTING
i_date TYPE datum
i_row TYPE zexcel_cell_row
i_col TYPE zexcel_cell_column_alpha
i_style TYPE zexcel_cell_style
CHANGING
c_worksheet TYPE REF TO zcl_excel_worksheet.
ENDCLASS. &quot;zcl_helper DEFINITION
*----------------------------------------------------------------------*
* CLASS zcl_helper IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zcl_helper IMPLEMENTATION.
METHOD load_image.
&quot;Load samle image
DATA: lt_bin TYPE solix_tab,
lv_len TYPE i.
CALL METHOD cl_gui_frontend_services=&gt;gui_upload
EXPORTING
filename = filename
filetype = &apos;BIN&apos;
IMPORTING
filelength = lv_len
CHANGING
data_tab = lt_bin
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
IF sy-subrc &lt;&gt; 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION &apos;SCMS_BINARY_TO_XSTRING&apos;
EXPORTING
input_length = lv_len
IMPORTING
buffer = r_image
TABLES
binary_tab = lt_bin
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc &lt;&gt; 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDMETHOD. &quot;load_image
METHOD add_calendar.
DATA: row TYPE zexcel_cell_row,
row_max TYPE i,
col_int TYPE zexcel_cell_column,
col_max TYPE i,
from_col_int TYPE zexcel_cell_column,
col TYPE zexcel_cell_column_alpha,
lr_col_dim TYPE REF TO zcl_excel_worksheet_columndime,
lr_row_dim TYPE REF TO zcl_excel_worksheet_rowdimensi.
DATA: lv_date TYPE datum,
value TYPE string,
weekday TYPE wotnr,
weekrow TYPE wotnr VALUE 1,
day TYPE i,
width TYPE f,
height TYPE f.
DATA: hyperlink TYPE REF TO zcl_excel_hyperlink.
DATA: day_names TYPE TABLE OF t246.
FIELD-SYMBOLS: &lt;day_name&gt; LIKE LINE OF day_names.
lv_date = i_date_from.
from_col_int = zcl_excel_common=&gt;convert_column2int( i_from_col ).
&quot; Add description for Calendar Week
c_worksheet-&gt;set_cell(
EXPORTING
ip_column = i_from_col &quot; Cell Column
ip_row = i_from_row &quot; Cell Row
ip_value = &apos;CW&apos;(001) &quot; Cell Value
ip_style = i_cw_style
).
&quot; Add Days
CALL FUNCTION &apos;DAY_NAMES_GET&apos;
TABLES
day_names = day_names.
LOOP AT day_names ASSIGNING &lt;day_name&gt;.
row = i_from_row.
col_int = from_col_int + &lt;day_name&gt;-wotnr.
col = zcl_excel_common=&gt;convert_column2alpha( col_int ).
value = &lt;day_name&gt;-langt.
c_worksheet-&gt;set_cell(
EXPORTING
ip_column = col &quot; Cell Column
ip_row = row &quot; Cell Row
ip_value = value &quot; Cell Value
ip_style = i_cw_style
).
ENDLOOP.
WHILE lv_date &lt;= i_date_to.
day = lv_date+6(2).
CALL FUNCTION &apos;FIMA_X_DAY_IN_MONTH_COMPUTE&apos;
EXPORTING
i_datum = lv_date
IMPORTING
e_wochentag_nr = weekday.
row = i_from_row + weekrow.
col_int = from_col_int + weekday.
col = zcl_excel_common=&gt;convert_column2alpha( col_int ).
value = day.
CONDENSE value.
c_worksheet-&gt;set_cell(
EXPORTING
ip_column = col &quot; Cell Column
ip_row = row &quot; Cell Row
ip_value = value &quot; Cell Value
ip_style = i_day_style &quot; Single-Character Indicator
).
IF weekday = 7.
&quot; Add Calender Week
zcl_helper=&gt;add_calender_week(
EXPORTING
i_date = lv_date
i_row = row
i_col = i_from_col
i_style = i_cw_style
CHANGING
c_worksheet = c_worksheet
).
weekrow = weekrow + 1.
ENDIF.
lv_date = lv_date + 1.
ENDWHILE.
&quot; Add Calender Week
zcl_helper=&gt;add_calender_week(
EXPORTING
i_date = lv_date
i_row = row
i_col = i_from_col
i_style = i_cw_style
CHANGING
c_worksheet = c_worksheet
).
&quot; Add Created with abap2xlsx
row = row + 2.
value = &apos;Created with abap2xlsx. Find more information at http://abap2xlsx.org.&apos;(002).
hyperlink = zcl_excel_hyperlink=&gt;create_external_link( &apos;http://abap2xlsx.org&apos; ). &quot;#EC NOTEXT
c_worksheet-&gt;set_cell(
EXPORTING
ip_column = i_from_col &quot; Cell Column
ip_row = row &quot; Cell Row
ip_value = value &quot; Cell Value
ip_hyperlink = hyperlink
).
col_int = from_col_int.
col_max = from_col_int + 7.
WHILE col_int &lt;= col_max.
col = zcl_excel_common=&gt;convert_column2alpha( col_int ).
IF sy-index = 1.
width = &apos;5.0&apos;.
ELSE.
width = &apos;11.4&apos;.
ENDIF.
lr_col_dim = c_worksheet-&gt;get_column_dimension( col ).
lr_col_dim-&gt;set_width( width ).
col_int = col_int + 1.
ENDWHILE.
row = i_from_row + 1.
row_max = i_from_row + 6.
WHILE row &lt;= row_max.
height = 50.
lr_row_dim = c_worksheet-&gt;get_row_dimension( row ).
lr_row_dim-&gt;set_row_height( height ).
row = row + 1.
ENDWHILE.
ENDMETHOD. &quot;add_calendar
METHOD add_calender_week.
DATA: week TYPE kweek,
week_int TYPE i,
value TYPE string.
&quot; Add Calender Week
CALL FUNCTION &apos;DATE_GET_WEEK&apos;
EXPORTING
date = i_date &quot; Date for which the week should be calculated
IMPORTING
week = week. &quot; Week for date (format:YYYYWW)
value = week+4(2).
week_int = value.
value = week_int.
CONDENSE value.
c_worksheet-&gt;set_cell(
EXPORTING
ip_column = i_col &quot; Cell Column
ip_row = i_row &quot; Cell Row
ip_value = value &quot; Cell Value
ip_style = i_style
).
ENDMETHOD. &quot;add_calender_week
ENDCLASS. &quot;zcl_helper IMPLEMENTATION</source>
</PROG>