14.01.2020 Views

ABAP_to_the_Future

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Enhancing Custom Reports with ABAP2XLSX 11.2

path in the middle of the footer, and the current page number (as in, page X of Y)

on the right in the footer.

Listing 11.11 fills up two structures: LS_HEADER and LS_FOOTER. These structures

have various fields for the left, center, and right of the header and footer. Change

the structures such that the worksheet na me is in the center of the header, and

then specify that the date goes on the left of the footer, the spreadsheet path goes

in the middle of the footer (there is a secret code used here called '&Z&F', which

stands for path/filename), and that the current page number should go on the

right of the footer (again using a secret code, 'page &P of &N' ). Once the two

structures are full, pass them into the SET_HEADER_FOOTER method to update the

worksheet object.

DATA: ls_header TYPE zexcel_s_worksheet_head_foot,

ls_footer TYPE zexcel_s_worksheet_head_foot,

ld_string TYPE string.

"Put Tab Name in Header Centre

ls_header-center_value = lo_worksheet->get_title( ).

ls_header-center_font = ls_header-right_font.

ls_header-center_font-size = 8.

ls_header-center_font-name = zcl_excel_style_font=>c_name_arial.

"Put generated date on footer left

CONCATENATE sy-datum+6(2) sy-datum+4(2) sy-datum(4) INTO ld_

string SEPARATED BY '/'.

ls_footer-left_value = ld_string.

ls_footer-left_font = ls_header-center_font.

"Put Spreadsheet path and name in Footer Centre

ls_footer-center_value = '&Z&F'.

"Path / Filename

ls_footer-center_font = ls_header-center_font.

"Put page X of Y on Footer Right

ls_footer-right_value = 'page &P of &N' ##no_text. "page x of y

ls_footer-right_font = ls_header-center_font.

lo_worksheet->sheet_setup->set_header_footer(

ip_odd_header = ls_header

ip_odd_footer = ls_footer ).

Listing 11.11 Coding Header and Footer Print Settings

In this example, the first row is the header row; say you want this to repeat at the

top of every sheet that’s printed. The code for this is shown in Listing 11.12.

473

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!