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

11.1.3 Creating XLSX Files Using ABAP

At a very high level, the process for crea ting XLSX files using ABAP is incredibly

simplistic, as simplistic as Jock McSi mplistic the simplistic Scotsman, winner of

the all-Scotland “being simplistic” contest. This process is depicted in Figure 11.6.

Create Excel Object

Add Desired

Attributes

Convert to XML

Download/Email/

Open in Place

Figure 11.6 High-Level ABAP2XLSX Process Flow

Each of the steps in the process are discussed in more detail next.

Creating the Excel Object

The first step in the process flow is to create an Excel object. (Section 11.2.1 adds

another step at the start of the process flow: taking an existing SAP report object

and converting it into an Excel object. However, for now you will start by creating

the Excel object from scratch.) In OO programming, classes represent realworld

objects, and in this case you have a class that is a representation of the realworld

object that is an Excel spreadshee t. Because building up an XML structure

manually can be quite cumbersome, workin g with an instance of such a class is

far easier.

A spreadsheet consists of one or more worksheets, so after you create your Excel

object you have to specify which worksheet you’re talking about. Naturally, the

default is the first worksheet, so that is the active one. In most spreadsheets, you

only have one worksheet. The code for creating the Excel object and navigating to

the first worksheet is shown in Listing 11.1.

DATA: lo_excel TYPE REF TO zcl_excel,

lo_worksheet TYPE REF TO zcl_excel_worksheet.

CREATE OBJECT lo_excel.

lo_worksheet = lo_excel->get_active_worksheet( ).

Listing 11.1 Creating the Excel Object and Navigating to the First Worksheet

462

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

Saved successfully!

Ooh no, something went wrong!