mirror of
https://github.com/abap2xlsx/abap2xlsx.git
synced 2025-05-05 05:12:03 +08:00
Created demo report ZDEMO_EXCEL24 to test solution of issue #47 with revision 78.
git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@113 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049
This commit is contained in:
parent
f050d256d0
commit
61045cc6ff
125
ZA2X/PROG/ZDEMO_EXCEL24.slnk
Normal file
125
ZA2X/PROG/ZDEMO_EXCEL24.slnk
Normal file
|
@ -0,0 +1,125 @@
|
|||
<?xml version="1.0" encoding="utf-16"?>
|
||||
<PROG NAME="ZDEMO_EXCEL24" VARCL="X" SUBC="1" CNAM="BCUSER" CDAT="20110129" UNAM="BCUSER" UDAT="20110129" VERN="000021" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20110129" STIME="174257" IDATE="20110129" ITIME="174257" UCCHECK="X">
|
||||
<textPool>
|
||||
<language SPRAS="E">
|
||||
<textElement ID="R" ENTRY="abap2xlsx Demo: Multiple sheets with different default date formats" LENGTH="70 "/>
|
||||
</language>
|
||||
</textPool>
|
||||
<programDocumentation/>
|
||||
<source>*&---------------------------------------------------------------------*
|
||||
*& Report ZDEMO_EXCEL23
|
||||
*&
|
||||
*&---------------------------------------------------------------------*
|
||||
*&
|
||||
*&
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
REPORT zdemo_excel24.
|
||||
|
||||
TYPE-POOLS: abap.
|
||||
|
||||
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,
|
||||
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: lv_default_file_name TYPE string VALUE '24_Sheets_with_different_default_date_formats.xlsx'.
|
||||
|
||||
PARAMETERS: p_path TYPE zexcel_export_dir.
|
||||
|
||||
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
|
||||
lv_workdir = p_path.
|
||||
cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir
|
||||
CHANGING selected_folder = lv_workdir ).
|
||||
p_path = lv_workdir.
|
||||
|
||||
INITIALIZATION.
|
||||
cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ).
|
||||
cl_gui_cfw=>flush( ).
|
||||
p_path = lv_workdir.
|
||||
|
||||
START-OF-SELECTION.
|
||||
|
||||
IF p_path IS INITIAL.
|
||||
p_path = lv_workdir.
|
||||
ENDIF.
|
||||
cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ).
|
||||
CONCATENATE p_path lv_file_separator lv_default_file_name INTO lv_full_path.
|
||||
|
||||
" Creates active sheet
|
||||
CREATE OBJECT lo_excel.
|
||||
|
||||
" Get active sheet
|
||||
lo_worksheet = lo_excel->get_active_worksheet( ).
|
||||
lo_worksheet->set_title( ip_title = 'Sheet1' ).
|
||||
lo_worksheet->set_cell( ip_column = 'A' ip_row = 1 ip_value = 'Default Date Format' ).
|
||||
" Insert current date
|
||||
lo_worksheet->set_cell( ip_column = 'A' ip_row = 3 ip_value = 'Current Date:' ).
|
||||
lo_worksheet->set_cell( ip_column = 'A' ip_row = 4 ip_value = sy-datum ).
|
||||
|
||||
lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet2!A1' ).
|
||||
lo_worksheet->set_cell( ip_column = 'A' ip_row = 6 ip_value = 'This is a link to the second sheet' ip_hyperlink = lo_hyperlink ).
|
||||
column_dimension = lo_worksheet->get_column_dimension( ip_column = 'A' ).
|
||||
column_dimension->set_auto_size( ip_auto_size = abap_true ).
|
||||
|
||||
|
||||
" Second sheet
|
||||
lo_worksheet = lo_excel->add_new_worksheet( ).
|
||||
lo_worksheet->set_default_excel_date_format( zcl_excel_style_number_format=>c_format_date_yyyymmdd ).
|
||||
lo_worksheet->set_title( ip_title = 'Sheet2' ).
|
||||
lo_worksheet->set_cell( ip_column = 'A' ip_row = 1 ip_value = 'Date Format set to YYYYMMDD' ).
|
||||
" Insert current date
|
||||
lo_worksheet->set_cell( ip_column = 'A' ip_row = 3 ip_value = 'Current Date:' ).
|
||||
lo_worksheet->set_cell( ip_column = 'A' ip_row = 4 ip_value = sy-datum ).
|
||||
|
||||
lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet3!B2' ).
|
||||
lo_worksheet->set_cell( ip_column = 'A' ip_row = 6 ip_value = 'This is link to the third sheet' ip_hyperlink = lo_hyperlink ).
|
||||
|
||||
" Third sheet
|
||||
lo_worksheet = lo_excel->add_new_worksheet( ).
|
||||
" TODO: It seems that the zcl_excel_style_number_format=>c_format_date_yyyymmddslash
|
||||
" does not produce a valid output
|
||||
" lo_worksheet->set_default_excel_date_format( zcl_excel_style_number_format=>c_format_date_yyyymmddslash ).
|
||||
lo_worksheet->set_title( ip_title = 'Sheet3' ).
|
||||
lo_worksheet->set_cell( ip_column = 'A' ip_row = 1 ip_value = 'Date Format set to YYYY/MM/DD' ).
|
||||
" Insert current date
|
||||
lo_worksheet->set_cell( ip_column = 'A' ip_row = 3 ip_value = 'Current Date:' ).
|
||||
lo_worksheet->set_cell( ip_column = 'A' ip_row = 4 ip_value = sy-datum ).
|
||||
|
||||
lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet1!B2' ).
|
||||
lo_worksheet->set_cell( ip_column = 'A' ip_row = 6 ip_value = 'This is link to the first sheet' ip_hyperlink = lo_hyperlink ).
|
||||
|
||||
lo_excel->set_active_sheet_index_by_name( 'Sheet1' ).
|
||||
|
||||
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
|
||||
lv_file = lo_excel_writer->write_file( io_excel = lo_excel ).
|
||||
|
||||
" Convert to binary
|
||||
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
|
||||
EXPORTING
|
||||
buffer = lv_file
|
||||
IMPORTING
|
||||
output_length = lv_bytecount
|
||||
TABLES
|
||||
binary_tab = lt_file_tab.
|
||||
* " This method is only available on AS ABAP > 6.40
|
||||
* lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ).
|
||||
* lv_bytecount = xstrlen( lv_file ).
|
||||
|
||||
" Save the file
|
||||
cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount
|
||||
filename = lv_full_path
|
||||
filetype = 'BIN'
|
||||
CHANGING data_tab = lt_file_tab ).</source>
|
||||
</PROG>
|
Loading…
Reference in New Issue
Block a user