14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Enhancing Custom Reports with ABAP2XLSX 11.2

Retrieving the Template from a Custom Report

Now, you’ll modify the monster example report so that instead of creating a new

workbook you will instead start by retr ieving your example template from the

database. Put a checkbox on the front screen to let the user decide if he wants to

use the template with macros. Listing 11.2 8 performs a database read to get the

template in XSTRING format and then converts it into an Excel object. Then, create

a worksheet object; the Excel and worksheet objects, taken together, will make all

the difference when you call the CONVERTER.

*---------------------------------------------------------------*

* Retrieve template from the database

*---------------------------------------------------------------*

DATA: ls_template TYPE ztexcel_template,

lo_excel_reader TYPE REF TO zif_excel_reader,

lo_worksheet TYPE REF TO zcl_excel_worksheet.

IF p_macro = abap_true.

CREATE OBJECT lo_excel_reader TYPE zcl_excel_reader_xlsm.

SELECT SINGLE *

FROM ztexcel_template

INTO CORRESPONDING FIELDS OF ls_template

WHERE template_name = 'MONSTER_EXAMPLE'.

lo_excel = lo_excel_reader->load( ls_template-raw_data ).

lo_worksheet = lo_excel->get_active_worksheet( ).

ENDIF. "Do we want to use a macro?

Listing 11.28 Uploading an Excel Template

Now you have an Excel object and a wo rksheet object; they’re empty, but they

have macros hiding within them. Listing 11.29 fills up the blank worksheets with

report data by using the CONVERTER mentioned in Section 11.2.1.

lo_converter->convert(

EXPORTING

io_alv = go_view->mo_alv_grid

it_table = gt_monsters[]

i_table = abap_true

i_style_table = zcl_excel_table=>builtinstyle_medium2

io_worksheet = lo_worksheet

CHANGING

co_excel = lo_excel ).

Listing 11.29 Filling the Macro-Enabled Worksheet with Data

491

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

Saved successfully!

Ooh no, something went wrong!