mirror of
https://github.com/abap2xlsx/abap2xlsx.git
synced 2025-05-05 20:29:45 +08:00

git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@80 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049
150 lines
5.4 KiB
XML
150 lines
5.4 KiB
XML
<?xml version="1.0" encoding="utf-16"?>
|
|
<PROG NAME="ZDEMO_EXCEL16" VARCL="X" SUBC="1" CNAM="VONDRUSKA" CDAT="20100914" UNAM="FEMIA" UDAT="20101217" VERN="000056" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20101217" STIME="230849" IDATE="20101217" ITIME="230849" UCCHECK="X">
|
|
<textPool>
|
|
<language SPRAS="E">
|
|
<textElement ID="R" ENTRY="Test for excel - drawings" LENGTH="25 "/>
|
|
</language>
|
|
</textPool>
|
|
<source>*&---------------------------------------------------------------------*
|
|
*& Report ZIFE_TEST_EXCEL
|
|
*&
|
|
*&---------------------------------------------------------------------*
|
|
*&
|
|
*&
|
|
*&---------------------------------------------------------------------*
|
|
|
|
REPORT zdemo_excel16.
|
|
|
|
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,
|
|
column_dimension TYPE REF TO zcl_excel_worksheet_columndime.
|
|
|
|
DATA: lv_file TYPE xstring,
|
|
lv_bytecount TYPE i,
|
|
lt_file_tab TYPE solix_tab.
|
|
|
|
DATA: lv_workdir TYPE string,
|
|
lv_file_separator TYPE c.
|
|
|
|
CONSTANTS: lv_default_file_name TYPE string VALUE '16_Drawings.xlsx'.
|
|
|
|
PARAMETERS: p_path TYPE string.
|
|
|
|
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
|
|
|
|
cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = p_path
|
|
CHANGING selected_folder = p_path ).
|
|
|
|
INITIALIZATION.
|
|
cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ).
|
|
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 p_path.
|
|
|
|
" Creates active sheet
|
|
CREATE OBJECT lo_excel.
|
|
|
|
"Load samle image
|
|
DATA: lt_bin TYPE solix_tab,
|
|
lv_len TYPE i,
|
|
lv_content TYPE xstring,
|
|
ls_key TYPE wwwdatatab.
|
|
|
|
CALL METHOD cl_gui_frontend_services=>gui_upload
|
|
EXPORTING
|
|
filename = 'c:\Program Files\SAP\FrontEnd\SAPgui\wwi\graphics\W_bio.bmp'
|
|
filetype = 'BIN'
|
|
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 <> 0.
|
|
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
|
|
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
|
|
ENDIF.
|
|
|
|
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
|
|
EXPORTING
|
|
input_length = lv_len
|
|
IMPORTING
|
|
buffer = lv_content
|
|
TABLES
|
|
binary_tab = lt_bin
|
|
EXCEPTIONS
|
|
failed = 1
|
|
OTHERS = 2.
|
|
|
|
" Get active sheet
|
|
lo_worksheet = lo_excel->get_active_worksheet( ).
|
|
lo_worksheet->set_title( 'Sheet1' ).
|
|
lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Image from web repository (SMW0)' ).
|
|
|
|
" create global drawing, set position and media from web repository
|
|
lo_drawing = lo_excel->add_new_drawing( ).
|
|
lo_drawing->set_position( ip_from_row = 3
|
|
ip_from_col = 'B' ).
|
|
|
|
ls_key-relid = 'MI'.
|
|
ls_key-objid = 'SAPLOGO.GIF'.
|
|
lo_drawing->set_media_www( ip_key = ls_key
|
|
ip_width = 166
|
|
ip_height = 75 ).
|
|
|
|
" assign drawing to the worksheet
|
|
lo_worksheet->add_drawing( lo_drawing ).
|
|
|
|
" another drawing from a XSTRING read from a file
|
|
lo_worksheet->set_cell( ip_column = 'B' ip_row = 8 ip_value = 'Image from a file (c:\Program Files\SAP\FrontEnd\SAPgui\wwi\graphics\W_bio.bmp)' ).
|
|
lo_drawing = lo_excel->add_new_drawing( ).
|
|
lo_drawing->set_position( ip_from_row = 9
|
|
ip_from_col = 'B' ).
|
|
lo_drawing->set_media( ip_media = lv_content
|
|
ip_media_type = 'bmp'
|
|
ip_width = 83
|
|
ip_height = 160 ).
|
|
|
|
lo_worksheet->add_drawing( lo_drawing ).
|
|
|
|
|
|
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
|
|
lv_file = lo_excel_writer->write_file( lo_excel ).
|
|
|
|
* Convert to binary
|
|
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 = p_path
|
|
filetype = 'BIN'
|
|
CHANGING data_tab = lt_file_tab ).</source>
|
|
</PROG>
|