abap2xlsx/ZA2X/PROG/ZDEMO_EXCEL26.slnk
Ivan Femia b7481a4077 Issue #83 and issue #90 fixed
git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@169 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049
2011-05-04 19:15:49 +00:00

104 lines
4.0 KiB
XML

<?xml version="1.0" encoding="utf-16"?>
<PROG NAME="ZDEMO_EXCEL26" VARCL="X" SUBC="1" CNAM="FEMIA" CDAT="20100711" UNAM="FEMIA" UDAT="20110504" VERN="000065" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20110504" STIME="211130" IDATE="20110504" ITIME="211130" UCCHECK="X">
<textPool>
<language SPRAS="E">
<textElement ID="R" ENTRY="abap2xlsx Demo: Hello World" LENGTH="27 "/>
<textElement ID="S" KEY="P_PATH" ENTRY="D ." LENGTH="24 "/>
<textElement ID="S" KEY="P_READER" ENTRY=" Write back after using Reader" LENGTH="37 "/>
</language>
</textPool>
<source>*&amp;---------------------------------------------------------------------*
*&amp; Report ZDEMO_EXCEL26
*&amp;
*&amp;---------------------------------------------------------------------*
*&amp;
*&amp;
*&amp;---------------------------------------------------------------------*
REPORT zdemo_excel26.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_excel_writer TYPE REF TO zif_excel_writer,
lo_excel_reader TYPE REF TO zif_excel_reader.
DATA: lv_file TYPE xstring,
lv_bytecount TYPE i,
lt_file_tab TYPE solix_tab.
DATA: lv_full_path TYPE string,
lv_workdir TYPE string,
lv_file_separator TYPE c.
CONSTANTS: lv_demo01 TYPE string VALUE &apos;01_HelloWorld.xlsx&apos;.
CONSTANTS: lv_demo02 TYPE string VALUE &apos;02_Styles.xlsx&apos;.
PARAMETERS: p_path TYPE zexcel_export_dir.
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.
IF p_path IS INITIAL.
p_path = lv_workdir.
ENDIF.
cl_gui_frontend_services=&gt;get_file_separator( CHANGING file_separator = lv_file_separator ).
* Demo01
CONCATENATE p_path lv_file_separator lv_demo01 INTO lv_full_path.
CREATE OBJECT lo_excel_reader TYPE zcl_excel_reader_2007.
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
lo_excel = lo_excel_reader-&gt;load_file( lv_full_path ).
lv_file = lo_excel_writer-&gt;write_file( lo_excel ).
REPLACE &apos;.xlsx&apos; IN lv_full_path WITH &apos;FromReader.xlsx&apos;.
&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; 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 ).
* Demo02
CONCATENATE p_path lv_file_separator lv_demo02 INTO lv_full_path.
CREATE OBJECT lo_excel_reader TYPE zcl_excel_reader_2007.
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
lo_excel = lo_excel_reader-&gt;load_file( lv_full_path ).
lv_file = lo_excel_writer-&gt;write_file( lo_excel ).
REPLACE &apos;.xlsx&apos; IN lv_full_path WITH &apos;FromReader.xlsx&apos;.
&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; 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 ).</source>
</PROG>