abap2xlsx/ZA2X/PROG/ZDEMO_EXCEL24.slnk
Ivan 24c5fca308 Update slinkees
Update of all the slinkees files with the latest version of SAPLink to
simplify merge of pull request
2015-01-12 14:55:28 -06:00

120 lines
5.9 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<PROG NAME="ZDEMO_EXCEL24" VARCL="X" SUBC="1" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" UCCHECK="X">
<textPool>
<language SPRAS="E">
<textElement ID="R" ENTRY="abap2xlsx Demo: Multiple sheets with different default date formats" LENGTH="70 "/>
</language>
</textPool>
<source>*&amp;---------------------------------------------------------------------*
*&amp; Report ZDEMO_EXCEL23
*&amp;
*&amp;---------------------------------------------------------------------*
*&amp;
*&amp;
*&amp;---------------------------------------------------------------------*
REPORT zdemo_excel24.
TYPE-POOLS: abap.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_worksheet TYPE REF TO zcl_excel_worksheet,
column_dimension TYPE REF TO zcl_excel_worksheet_columndime,
lo_hyperlink TYPE REF TO zcl_excel_hyperlink.
DATA: lv_file TYPE xstring,
lv_bytecount TYPE i,
lt_file_tab TYPE solix_tab.
DATA: lv_full_path TYPE string,
lv_workdir TYPE string,
lv_file_separator TYPE c.
DATA: lv_value TYPE string.
CONSTANTS: gc_save_file_name TYPE string VALUE &apos;24_Sheets_with_different_default_date_formats.xlsx&apos;.
INCLUDE zdemo_excel_outputopt_incl.
START-OF-SELECTION.
&quot; Creates active sheet
CREATE OBJECT lo_excel.
&quot; Get active sheet
lo_worksheet = lo_excel-&gt;get_active_worksheet( ).
lo_worksheet-&gt;set_title( ip_title = &apos;Sheet1&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;A&apos; ip_row = 1 ip_value = &apos;Default Date Format&apos; ).
&quot; Insert current date
lo_worksheet-&gt;set_cell( ip_column = &apos;A&apos; ip_row = 3 ip_value = &apos;Current Date:&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;A&apos; ip_row = 4 ip_value = sy-datum ).
lo_hyperlink = zcl_excel_hyperlink=&gt;create_internal_link( iv_location = &apos;Sheet2!A1&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;A&apos; ip_row = 6 ip_value = &apos;This is a link to the second sheet&apos; ip_hyperlink = lo_hyperlink ).
column_dimension = lo_worksheet-&gt;get_column_dimension( ip_column = &apos;A&apos; ).
column_dimension-&gt;set_auto_size( ip_auto_size = abap_true ).
&quot; Second sheet
lo_worksheet = lo_excel-&gt;add_new_worksheet( ).
lo_worksheet-&gt;set_default_excel_date_format( zcl_excel_style_number_format=&gt;c_format_date_yyyymmdd ).
lo_worksheet-&gt;set_title( ip_title = &apos;Sheet2&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;A&apos; ip_row = 1 ip_value = &apos;Date Format set to YYYYMMDD&apos; ).
&quot; Insert current date
lo_worksheet-&gt;set_cell( ip_column = &apos;A&apos; ip_row = 3 ip_value = &apos;Current Date:&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;A&apos; ip_row = 4 ip_value = sy-datum ).
lo_hyperlink = zcl_excel_hyperlink=&gt;create_internal_link( iv_location = &apos;Sheet3!B2&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;A&apos; ip_row = 6 ip_value = &apos;This is link to the third sheet&apos; ip_hyperlink = lo_hyperlink ).
&quot; Third sheet
lo_worksheet = lo_excel-&gt;add_new_worksheet( ).
&quot; TODO: It seems that the zcl_excel_style_number_format=&gt;c_format_date_yyyymmddslash
&quot; does not produce a valid output
lo_worksheet-&gt;set_default_excel_date_format( zcl_excel_style_number_format=&gt;c_format_date_yyyymmddslash ).
lo_worksheet-&gt;set_title( ip_title = &apos;Sheet3&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;A&apos; ip_row = 1 ip_value = &apos;Date Format set to YYYY/MM/DD&apos; ).
&quot; Insert current date
lo_worksheet-&gt;set_cell( ip_column = &apos;A&apos; ip_row = 3 ip_value = &apos;Current Date:&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;A&apos; ip_row = 4 ip_value = sy-datum ).
lo_hyperlink = zcl_excel_hyperlink=&gt;create_internal_link( iv_location = &apos;Sheet4!B2&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;A&apos; ip_row = 6 ip_value = &apos;This is link to the 4th sheet&apos; ip_hyperlink = lo_hyperlink ).
&quot; 4th sheet
lo_worksheet = lo_excel-&gt;add_new_worksheet( ).
&quot; Illustrate the Problem caused by:
&quot; Excel 2000 incorrectly assumes that the year 1900 is a leap year.
&quot; http://support.microsoft.com/kb/214326/en-us
lo_worksheet-&gt;set_title( ip_title = &apos;Sheet4&apos; ).
&quot; Loop from Start Date to the Max Date current data in daily steps
CONSTANTS: lv_max type d VALUE &apos;19000302&apos;.
DATA: lv_date TYPE d VALUE &apos;19000226&apos;,
lv_row TYPE i.
lo_worksheet-&gt;set_cell( ip_column = &apos;B&apos; ip_row = 3 ip_value = &apos;Formated date&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;C&apos; ip_row = 3 ip_value = &apos;Integer value for this date&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;D&apos; ip_row = 3 ip_value = &apos;Date as string&apos; ).
lv_row = 4.
WHILE lv_date &lt; lv_max.
lo_worksheet-&gt;set_cell( ip_column = &apos;B&apos; ip_row = lv_row ip_value = lv_date ).
lv_value = zcl_excel_common=&gt;date_to_excel_string( lv_date ).
lo_worksheet-&gt;set_cell( ip_column = &apos;C&apos; ip_row = lv_row ip_value = lv_value ).
lv_value = lv_date.
lo_worksheet-&gt;set_cell( ip_column = &apos;D&apos; ip_row = lv_row ip_value = lv_value ).
lv_date = lv_date + 1.
lv_row = lv_row + 1.
ENDWHILE.
lv_row = lv_row + 1.
lo_hyperlink = zcl_excel_hyperlink=&gt;create_internal_link( iv_location = &apos;Sheet1!B2&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;A&apos; ip_row = lv_row ip_value = &apos;This is link to the first sheet&apos; ip_hyperlink = lo_hyperlink ).
lo_excel-&gt;set_active_sheet_index_by_name( &apos;Sheet1&apos; ).
*** Create output
lcl_output=&gt;output( lo_excel ).</source>
</PROG>