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.

11

ABAP2XLSX

settings. There is an attri bute of the worksheet object that is a structure called

SHEET_SETUP that’s filled with fields in which you can change assorted print settings.

Listing 11.10 first makes the page margins narrow (so that more can fit on

the printed page) by passing in various values to a method called SET_PAGE_MAR-

GINS. Then it changes some more fields in the SHEET_SETUP structure to make the

spreadsheet columns fit al l on one page and to change the orientation to landscape

(which is the most important thing accomplished in this code).

" Page printing settings

" Margins are to be set to the narrow values. Just copy

" the values in the narrow option on the print preview.

lo_worksheet->sheet_setup->set_page_margins(

ip_top = '1.91'

ip_bottom = '1.91'

ip_left = '0.64'

ip_right = '0.64'

ip_header = '0.76'

ip_footer = '0.76'

ip_unit = 'cm' ).

lo_worksheet->sheet_setup->black_and_white = abap_true.

"Requirement is to fit all columns on one sheet

lo_worksheet->sheet_setup->fit_to_page = abap_true. " you should

* turn this on to activate fit_to_height and fit_to_width

lo_worksheet->sheet_setup->fit_to_width = 1. " used only if ip_fit_

" to_page = 'X'

lo_worksheet->sheet_setup->orientation

= zcl_excel_sheet_setup=>c_orientation_landscape.

lo_worksheet->sheet_setup->page_order

= zcl_excel_sheet_setup=>c_ord_downthenover.

lo_worksheet->sheet_setup->paper_size

= zcl_excel_sheet_setup=>c_papersize_a4.

lo_worksheet->sheet_setup->scale

= 80. " used only if ip_fit_to_page = SPACE

lo_worksheet->sheet_setup->horizontal_centered = abap_true.

Listing 11.10 Programatically Changing the Print Orientation to Landscape

As mentioned earlier, the method names and attributes are all in plain English, so

it’s easy to tell what is going on.

Next, set up some headers and footers to be printed at the top and bottom of

every page; naturally, you can put anything you want in the headers and footers.

In this example, put the sp readsheet name in the center of the header, the date

the spreadsheet was generated on in the left of the footer, the spreadsheet file

472

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

Saved successfully!

Ooh no, something went wrong!