mirror of
https://github.com/abap2xlsx/abap2xlsx.git
synced 2025-05-05 11:06:15 +08:00
Fixed #145
git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@264 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049
This commit is contained in:
parent
9e766b5363
commit
ea9d9d300b
|
@ -1,117 +1,144 @@
|
||||||
<?xml version="1.0" encoding="utf-16"?>
|
<?xml version="1.0" encoding="utf-16"?>
|
||||||
<PROG NAME="ZDEMO_EXCEL4" VARCL="X" SUBC="1" CNAM="FEMIA" CDAT="20100711" UNAM="DEVELOPER" UDAT="20111229" VERN="000039" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20111229" STIME="193218" IDATE="20111229" ITIME="193218" UCCHECK="X">
|
<PROG NAME="ZDEMO_EXCEL4" VARCL="X" SUBC="1" CNAM="FEMIA" CDAT="20100711" UNAM="FEMIA" UDAT="20120316" VERN="000046" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20120316" STIME="090807" IDATE="20120316" ITIME="090807" UCCHECK="X">
|
||||||
<textPool>
|
<textPool>
|
||||||
<language SPRAS="E">
|
<language SPRAS="E">
|
||||||
<textElement ID="R" ENTRY="abap2xlsx Demo: Create XLXS with multiple sheets" LENGTH="48 "/>
|
<textElement ID="R" ENTRY="abap2xlsx Demo: Create XLXS with multiple sheets" LENGTH="48 "/>
|
||||||
</language>
|
<textElement ID="S" KEY="P_PATH" ENTRY="D ." LENGTH="9 "/>
|
||||||
</textPool>
|
</language>
|
||||||
<source>*&---------------------------------------------------------------------*
|
</textPool>
|
||||||
*& Report ZDEMO_EXCEL4
|
<source>*&---------------------------------------------------------------------*
|
||||||
*&
|
*& Report ZDEMO_EXCEL4
|
||||||
*&---------------------------------------------------------------------*
|
*&
|
||||||
*&
|
*&---------------------------------------------------------------------*
|
||||||
*&
|
*&
|
||||||
*&---------------------------------------------------------------------*
|
*&
|
||||||
|
*&---------------------------------------------------------------------*
|
||||||
REPORT zdemo_excel4.
|
|
||||||
|
REPORT zdemo_excel4.
|
||||||
DATA: lo_excel TYPE REF TO zcl_excel,
|
|
||||||
lo_excel_writer TYPE REF TO zif_excel_writer,
|
DATA: lo_excel TYPE REF TO zcl_excel,
|
||||||
lo_worksheet TYPE REF TO zcl_excel_worksheet,
|
lo_excel_writer TYPE REF TO zif_excel_writer,
|
||||||
lo_hyperlink TYPE REF TO zcl_excel_hyperlink.
|
lo_worksheet TYPE REF TO zcl_excel_worksheet,
|
||||||
|
lo_hyperlink TYPE REF TO zcl_excel_hyperlink.
|
||||||
DATA: lv_file TYPE xstring,
|
|
||||||
lv_bytecount TYPE i,
|
DATA: lv_file TYPE xstring,
|
||||||
lt_file_tab TYPE solix_tab.
|
lv_bytecount TYPE i,
|
||||||
|
lt_file_tab TYPE solix_tab.
|
||||||
DATA: lv_full_path TYPE string,
|
|
||||||
lv_workdir TYPE string,
|
DATA: lv_full_path TYPE string,
|
||||||
lv_file_separator TYPE c.
|
lv_workdir TYPE string,
|
||||||
|
lv_file_separator TYPE c.
|
||||||
CONSTANTS: lv_default_file_name TYPE string VALUE '04_Sheets.xlsx'.
|
|
||||||
|
DATA: ls_header TYPE zexcel_s_worksheet_head_foot,
|
||||||
PARAMETERS: p_path TYPE zexcel_export_dir.
|
ls_footer TYPE zexcel_s_worksheet_head_foot.
|
||||||
|
|
||||||
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
|
CONSTANTS: lv_default_file_name TYPE string VALUE '04_Sheets.xlsx'.
|
||||||
lv_workdir = p_path.
|
|
||||||
cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir
|
PARAMETERS: p_path TYPE zexcel_export_dir.
|
||||||
CHANGING selected_folder = lv_workdir ).
|
|
||||||
p_path = lv_workdir.
|
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
|
||||||
|
lv_workdir = p_path.
|
||||||
INITIALIZATION.
|
cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir
|
||||||
cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ).
|
CHANGING selected_folder = lv_workdir ).
|
||||||
cl_gui_cfw=>flush( ).
|
p_path = lv_workdir.
|
||||||
p_path = lv_workdir.
|
|
||||||
|
INITIALIZATION.
|
||||||
START-OF-SELECTION.
|
cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ).
|
||||||
|
cl_gui_cfw=>flush( ).
|
||||||
IF p_path IS INITIAL.
|
p_path = lv_workdir.
|
||||||
p_path = lv_workdir.
|
|
||||||
ENDIF.
|
START-OF-SELECTION.
|
||||||
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.
|
IF p_path IS INITIAL.
|
||||||
|
p_path = lv_workdir.
|
||||||
" Creates active sheet
|
ENDIF.
|
||||||
CREATE OBJECT lo_excel.
|
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.
|
||||||
" Get active sheet
|
|
||||||
lo_worksheet = lo_excel->get_active_worksheet( ).
|
" Creates active sheet
|
||||||
lo_worksheet->set_title( ip_title = 'Sheet1' ).
|
CREATE OBJECT lo_excel.
|
||||||
lo_worksheet->zif_excel_sheet_properties~selected = zif_excel_sheet_properties=>c_selected.
|
|
||||||
lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the first sheet' ).
|
" Get active sheet
|
||||||
lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet2!B2' ).
|
lo_worksheet = lo_excel->get_active_worksheet( ).
|
||||||
lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'This is link to second sheet' ip_hyperlink = lo_hyperlink ).
|
lo_worksheet->set_title( ip_title = 'Sheet1' ).
|
||||||
|
lo_worksheet->zif_excel_sheet_properties~selected = zif_excel_sheet_properties=>c_selected.
|
||||||
lo_worksheet->sheet_setup->set_page_margins( ip_header = '1' ip_footer = '1' ip_unit = 'cm' ).
|
lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the first sheet' ).
|
||||||
lo_worksheet->sheet_setup->black_and_white = 'X'.
|
lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet2!B2' ).
|
||||||
lo_worksheet->sheet_setup->fit_to_page = 'X'. " you should turn this on to activate fit_to_height and fit_to_width
|
lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'This is link to second sheet' ip_hyperlink = lo_hyperlink ).
|
||||||
lo_worksheet->sheet_setup->fit_to_height = 0. " used only if ip_fit_to_page = 'X'
|
|
||||||
lo_worksheet->sheet_setup->fit_to_width = 2. " used only if ip_fit_to_page = 'X'
|
|
||||||
lo_worksheet->sheet_setup->orientation = zcl_excel_sheet_setup=>c_orientation_landscape.
|
" Page printing settings
|
||||||
lo_worksheet->sheet_setup->page_order = zcl_excel_sheet_setup=>c_ord_downthenover.
|
lo_worksheet->sheet_setup->set_page_margins( ip_header = '1' ip_footer = '1' ip_unit = 'cm' ).
|
||||||
lo_worksheet->sheet_setup->paper_size = zcl_excel_sheet_setup=>c_papersize_a4.
|
lo_worksheet->sheet_setup->black_and_white = 'X'.
|
||||||
lo_worksheet->sheet_setup->scale = 80. " used only if ip_fit_to_page = SPACE
|
lo_worksheet->sheet_setup->fit_to_page = 'X'. " you should turn this on to activate fit_to_height and fit_to_width
|
||||||
|
lo_worksheet->sheet_setup->fit_to_height = 0. " used only if ip_fit_to_page = 'X'
|
||||||
|
lo_worksheet->sheet_setup->fit_to_width = 2. " used only if ip_fit_to_page = 'X'
|
||||||
|
lo_worksheet->sheet_setup->orientation = zcl_excel_sheet_setup=>c_orientation_landscape.
|
||||||
lo_worksheet = lo_excel->add_new_worksheet( ).
|
lo_worksheet->sheet_setup->page_order = zcl_excel_sheet_setup=>c_ord_downthenover.
|
||||||
lo_worksheet->set_title( ip_title = 'Sheet2' ).
|
lo_worksheet->sheet_setup->paper_size = zcl_excel_sheet_setup=>c_papersize_a4.
|
||||||
lo_worksheet->zif_excel_sheet_properties~selected = zif_excel_sheet_properties=>c_selected.
|
lo_worksheet->sheet_setup->scale = 80. " used only if ip_fit_to_page = SPACE
|
||||||
lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the second sheet' ).
|
|
||||||
lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet1!B2' ).
|
" Header and Footer
|
||||||
lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'This is link to first sheet' ip_hyperlink = lo_hyperlink ).
|
ls_header-right_value = 'print date &D'.
|
||||||
lo_worksheet->set_cell( ip_column = 'B' ip_row = 4 ip_value = 'Sheet3 is hidden' ).
|
ls_header-right_font-size = 8.
|
||||||
|
ls_header-right_font-name = zcl_excel_style_font=>c_name_arial.
|
||||||
lo_worksheet = lo_excel->add_new_worksheet( ).
|
|
||||||
lo_worksheet->set_title( ip_title = 'Sheet3' ).
|
ls_footer-left_value = '&Z&F'. "Path / Filename
|
||||||
lo_worksheet->zif_excel_sheet_properties~hidden = zif_excel_sheet_properties=>c_hidden.
|
ls_footer-left_font = ls_header-right_font.
|
||||||
|
ls_footer-right_value = 'page &P of &N'. "page x of y
|
||||||
lo_worksheet = lo_excel->add_new_worksheet( ).
|
ls_footer-right_font = ls_header-right_font.
|
||||||
lo_worksheet->set_title( ip_title = 'Sheet4' ).
|
|
||||||
lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Cell B3 has value 0' ).
|
lo_worksheet->sheet_setup->set_header_footer( ip_odd_header = ls_header
|
||||||
lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 0 ).
|
ip_odd_footer = ls_footer ).
|
||||||
lo_worksheet->zif_excel_sheet_properties~show_zeros = zif_excel_sheet_properties=>c_hidezero.
|
|
||||||
|
|
||||||
lo_excel->set_active_sheet_index_by_name( 'Sheet1' ).
|
lo_worksheet = lo_excel->add_new_worksheet( ).
|
||||||
|
lo_worksheet->set_title( ip_title = 'Sheet2' ).
|
||||||
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
|
lo_worksheet->zif_excel_sheet_properties~selected = zif_excel_sheet_properties=>c_selected.
|
||||||
lv_file = lo_excel_writer->write_file( lo_excel ).
|
lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the second sheet' ).
|
||||||
|
lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet1!B2' ).
|
||||||
" Convert to binary
|
lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'This is link to first sheet' ip_hyperlink = lo_hyperlink ).
|
||||||
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
|
lo_worksheet->set_cell( ip_column = 'B' ip_row = 4 ip_value = 'Sheet3 is hidden' ).
|
||||||
EXPORTING
|
|
||||||
buffer = lv_file
|
lo_worksheet->sheet_setup->set_header_footer( ip_odd_header = ls_header
|
||||||
IMPORTING
|
ip_odd_footer = ls_footer ).
|
||||||
output_length = lv_bytecount
|
|
||||||
TABLES
|
lo_worksheet = lo_excel->add_new_worksheet( ).
|
||||||
binary_tab = lt_file_tab.
|
lo_worksheet->set_title( ip_title = 'Sheet3' ).
|
||||||
* " This method is only available on AS ABAP > 6.40
|
lo_worksheet->zif_excel_sheet_properties~hidden = zif_excel_sheet_properties=>c_hidden.
|
||||||
* lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ).
|
|
||||||
* lv_bytecount = xstrlen( lv_file ).
|
lo_worksheet->sheet_setup->set_header_footer( ip_odd_header = ls_header
|
||||||
|
ip_odd_footer = ls_footer ).
|
||||||
" Save the file
|
|
||||||
cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount
|
lo_worksheet = lo_excel->add_new_worksheet( ).
|
||||||
filename = lv_full_path
|
lo_worksheet->set_title( ip_title = 'Sheet4' ).
|
||||||
filetype = 'BIN'
|
lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Cell B3 has value 0' ).
|
||||||
CHANGING data_tab = lt_file_tab ).</source>
|
lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 0 ).
|
||||||
</PROG>
|
lo_worksheet->zif_excel_sheet_properties~show_zeros = zif_excel_sheet_properties=>c_hidezero.
|
||||||
|
|
||||||
|
lo_worksheet->sheet_setup->set_header_footer( ip_odd_header = ls_header
|
||||||
|
ip_odd_footer = ls_footer ).
|
||||||
|
|
||||||
|
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( 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