An example programs

Data declaration

This framework mainly relies on two classes, which are  LCL_EXCEL and LCL_RANGE.

There are other classes described under “Reference to classes  used”, but they will not be used directly.

  Class LCL_EXCEL represents the Excel application. It initializes the Excel application on frontend and creates workbook and worksheet objects.

Onother use of this class is to create objects of type LCL_RANGE.

class LCL_RANGE represents either a cell or a collection of cells. All the data will be inserted and all the formatting will be carried out through this class.

   data: LO_EXCEL type ref to LCL_EXCEL.

data: LO_RANGE type ref to LCL_RANGE.

data: LO_PARENT type ref to LCL_RANGE.

data: LT_TEXTS type standard table of STRING.

data: L_TEXT type STRING.

data: L_OFFSET type STRING.

data: L_HEADER type STRING.

data: begin of LS_DATA,

A type STRING,

B type STRING,

C type STRING,

D type STRING,

E type STRING,

F type STRING,

end of LS_DATA.

data: LT_DATA like standard table of LS_DATA.

LS_DATA-A = ‘A1’.

LS_DATA-B = ‘B1’.

LS_DATA-C = ‘C1’.

LS_DATA-D = ‘D1’.

LS_DATA-E = ‘E1’.

LS_DATA-F = ‘F1’.

append  LS_DATA to LT_DATA.

LS_DATA-A = ‘A2’.

LS_DATA-B = ‘B2’.

LS_DATA-C = ‘C2’.

LS_DATA-D = ‘D2’.

LS_DATA-E = ‘E2’.

LS_DATA-F = ‘F2’.

append  LS_DATA to LT_DATA.

Creating a single cell and passing data to it.

   create object LO_EXCEL.” Create an excel object

LO_EXCEL->;INITIALIZE( ). ” This method starts excel at frontend and creates workbook and a single sheet objects

LO_RANGE = LO_EXCEL->PREP_RANGE(

I_NAME  = ‘ CELL1’

I_TOP = 2

I_LEFT = 2

).

* Method  PREP_RANGE  creates a range object inside the sheet which represents a cell.

* The range has a name which can be used to retrieve it again from  LO_EXCEL object.

* All created range objects are stored in LO_EXCEL object and can be retrieved with method GET_RANGE  of  LO_EXCEL by the name passed to  I_NAME .

* Parameter I_TOP is an offset from the top of excel sheet

* Parameter I_LEFT is an offset from the left side of excel sheet

LO_RANGE->insert_value(‘Test 1’).

LO_EXCEL->SHOW( ). ” displays the result, without it the document will no be displayed

LO_EXCEL->CLEAR( ). ” frees all the objects

And the result will be :

TEST1.png

Creating a simple form with relative addressing and applying some formatting

LO_EXCEL->INITIALIZE( ).

* Create a range which starts at cell B2 and ends at E3

 

LO_PARENT = LO_EXCEL->PREP_RANGE(

I_NAME  = ‘Form’

I_TOP = 2

I_LEFT = 2

I_depth = 2

I_width = 4

).

* Add two blocks which span 2 columns to the first row of this form

LO_RANGE = LO_EXCEL->SUB_RANGE(

I_FROM = LO_PARENT

I_PARENT =‘Form’

I_NAME  = ‘BLOCK1’

I_WIDTH = 2

).

* Method sub_range creates a range which starts at the same top and left coordinates as range “Form” but ends at cell C2.

* I_parent is not mandatory it is only required to differentiate between subranges with same name but different parents

* The parameter I_FROM is required to be able to identify relative to what range we are creating our subrange

LO_RANGE = LO_EXCEL->;RT_OFF(

I_FROM = LO_RANGE

I_PARENT =‘Form’

I_NAME  = ‘BLOCK2’

I_WIDTH = 2

).

*  RT in method name stands for Right Top side of range “BLOCK1”

*  Depth is set by default to 1 and the top and left coordinates are derived relative to  “block1”

* Add formatting and texts to the form

LO_RANGE = LO_EXCEL->GET_RANGE(

I_PARENT = ‘Form’    ” names are case sensitive

I_NAME = ‘BLOCK1’

).

LO_RANGE->merge( ).

LO_RANGE->SET_BORDER( I_BAROUND = ABAP_TRUE ).

LO_RANGE->insert_value( ‘colspan A’ ).

LO_RANGE = LO_EXCEL->GET_RANGE(

I_PARENT = ‘Form’

I_NAME = ‘BLOCK2’

).

LO_RANGE->merge( ).

LO_RANGE->SET_BORDER( I_BAROUND = ABAP_TRUE ).

LO_RANGE->insert_value( ‘colspan B’ ).

LO_PARENT = LO_EXCEL->GET_RANGE(

I_NAME = ‘Form’

).

LO_PARENT->SET_BORDER(

I_WEIGHT = LO_PARENT->;C_THICK

I_BAROUND = ABAP_TRUE ).

LO_EXCEL->SHOW( ).

LO_EXCEL->CLEAR( ).

This will generate a sheet with output like this:

Test 2.png

If you need to reallocate the form to a different position on sheet you only have to change the coordinates of “Form” range.

Subranges and formatting will reallocate relative to  “Form” range.

Inserting a table into a sheet

*Declare additional variables:

data: LO_DUTIL type REF TO LCL_DATA_UTIL. ” This class will store named descriptions of table and structure elements

*Fill header structure of table

 

clear: LS_DATA.

LS_DATA-A = ‘Column A’.

LS_DATA-B = ‘Column B’.

LS_DATA-C = ‘Column C’.

LS_DATA-D = ‘Column D’.

LS_DATA-E = ‘Column E’.

LS_DATA-F = ‘Column F’.

*store Its description

LO_DUTIL = LCL_DATA_UTIL=>GET_INSTANCE( ).

LO_DUTIL->SET_STRUCT_DESCR(

PIS_STRUCT = LS_DATA

PI_NAME = ‘HEADER’

).

* Store the description of table

LO_DUTIL->SET_TAB_DESCR(

PIT_TAB = LT_DATA

PI_NAME = ‘G_TAB’

).

*Prepare ranges

LO_PARENT = LO_EXCEL->PREP_RANGE(

I_NAME  = ‘HEADER’

I_TOP = 2

I_LEFT = 2

I_WIDTH = 6

I_sname = ‘HEADER’ ” reference structure

).

LO_RANGE = LO_EXCEL->LB_OFF(  ” LB stands for Left Bottom side of reference range

I_FROM = LO_PARENT

I_NAME  = ‘TABLE’

I_WIDTH = 6

I_Depth = 2

I_sname = ‘G_TAB’ ” reference structure

).

* Add formatting and data

LO_PARENT->PASTE_STRUC( LS_DATA ).

LO_PARENT->SET_BORDER( ).

LO_PARENT->BOLD( ).

LO_PARENT->SET_FONT( 12 ). ” font size

LO_PARENT->WRAP_TEXT( ).

LO_PARENT->AUTOFIT( ).

LO_RANGE->PASTE_TABLE( LT_DATA ).

LO_RANGE->SET_BORDER( ).

LO_RANGE->SET_FONT( 8 ). ” font size

 

The result will be a simple table:

Test 3.png

 

Inserting table whose output structure does not correspond to the structure of data table

* Create reference output structure

data: begin of LS_OUTPUT,

F type STRING,

B type STRING,

D type STRING,

C type STRING,

E type STRING,

A type STRING,

end of LS_OUTPUT.

* Give it a name

LO_DUTIL->SET_STRUCT_DESCR(

PIS_STRUCT = LS_OUTPUT

PI_NAME = ‘OUTPUT’

).

* Pass the name of structure to ranges

LO_PARENT = LO_EXCEL->PREP_RANGE(

I_NAME  = ‘HEADER’

I_TOP = 4

I_LEFT = 3

I_WIDTH = 6

I_sname = ‘OUTPUT’

).

LO_RANGE = LO_EXCEL->LB_OFF(

I_FROM = LO_PARENT

I_NAME  = ‘TABLE’

I_WIDTH = 6

I_Depth = 2

I_sname = ‘OUTPUT’

).

* the output will be rearranged

Test 4.png

Choosing columns to display

* Additional data declaration

data: LO_DDESC type ref to LCL_DATA_DESCRIPTION. “this class represents the specific reference structure

* Select only the specific columns

LO_DDESC = LO_DUTIL->GET_DDESCR( ‘OUTPUT’ ).

*  Conversion of the table to text is carried out automatically

*  Class  LCL_STRUCT_UTIL contains various methods that work with structures registered with LCL_DATA_UTIL

*  Every method of LCL_STRUCT_UTIL has a corresponding code. In our case it is  “CT_TEXT” .

*  Every  method can have list of data elements that can be included or excluded from processing.

LO_DDESC->ADD_EXPTION(

PI_OP_NAME = ‘CT_TEXT’

PI_DELEM = ‘F’

PI_INCLUDE = ABAP_TRUE ).

LO_DDESC->ADD_EXPTION(

PI_OP_NAME = ‘CT_TEXT’

PI_DELEM = ‘D’

).

LO_DDESC->ADD_EXPTION(

PI_OP_NAME = ‘CT_TEXT’

PI_DELEM = ‘A’

).

* Adjust the range objects

LO_PARENT = LO_EXCEL->PREP_RANGE(

I_NAME  = ‘HEADER’

I_TOP = 4

I_LEFT = 3

I_WIDTH = 3

I_sname = ‘OUTPUT’

).

LO_RANGE = LO_EXCEL->LB_OFF(

I_FROM = LO_PARENT

I_NAME  = ‘TABLE’

I_WIDTH = 3

I_Depth = 2

I_sname = ‘OUTPUT’

).

* This will produce:

Test 5.png

Notice that the order of columns is maintained.  Instead of PI_INCLUDE  you can set PI_exclude flag to drop data elements from output.

Formatting specific columns or rows of table

* Additional data declaration

   data: LO_ROW type ref to LCL_RANGE.

data: LO_COLUMN type ref to LCL_RANGE.

data: LO_ITEM type ref to LCL_RANGE.

* Application of  special formatting to rows and columns

LO_COLUMN = LO_EXCEL->GET_COLUMN(

I_FROM = LO_RANGE

I_NUMBER = 2 ).

LO_COLUMN->SET_ALIGN( LO_COLUMN->C_CENTER ).

LO_ROW = LO_EXCEL->GET_ROW(

I_FROM = LO_RANGE

I_NUMBER = 2 ).

LO_ROW->ITALIC( ).

do 3 times.

LO_ITEM = LO_EXCEL->GET_ITEM(

I_FROM = LO_ROW

I_NUMBER = sy-index

).

LO_ITEM->SET_FONT( I_FCOLOUR = sy-index + 2 ).

enddo.

This will produce:

Test 6.png

Additional notes.

On performance.

I haven’t done any measurements, but subjectively it feels faster than using ole calls without no flush.

The issue with no flush is that it can create random errors if you are not careful with variable use and their lifetime.

You have to make sure that the result of previous method call is not overwritten by the following call.

This is why i feel that using OO abap for OLE automation is superior to procedural ABAP.

You can encapsulate every  range object of Excel application inside corresponding Abap Range class.

All the child objects of Range object can be assigned to unique attributes and this

will guarantee that you will not overwrite previous results of method calls.

All the instances of range class will live as long as you have references to them.

In my implementation all the instances of Range object are stored in internal table of LCL_EXCEL.

This table is only cleared when you call method Free of LCL_EXCEL.

This also assures that as long as program doesn’t terminates abnormally all the objects will be freed.

On extending this framework.

You can use macros recording to understand how various functions work on excel.

Another way is to search for Excel object model in msdn. It contains complete description of Application ,

Workbook ,Worksheet and Range objects. You can see al the methods and attributes that can be used.

It was very helpful for me in understanding how ole automation works.

Additionally this framework can be used with sap doi.

The interface i_oi_document_proxy has a method get_document_handle.

With this handle you can get reference to application object of sap doi.

call function ‘CONTROL_GET_PROPERTY’

exporting

h_control         = co_handle

property          = ‘Application’

no_flush          = abap_true

changing

return            = co_excel_application

exceptions

cntl_system_error = 1

cntl_error        = 2

others            = 3.

I used the function above to get the reference to application object and call methods to merge and

apply formatting to excel  displayed in place with my  framework.

But i was not able to paste table with export to clipboard.

I didn’t have time to investigate what was wrong  so it is up to you if you want to explore  further.

Reference to classes used

class LCL_DATA_ROOT

class LCL_DATA_ROOT definition.

public section.

type-pools: ABAP.

protected section.

types: begin of CY_DATE,

Y(4) type N,

M(2) type N,

D(2) type N,

end of CY_DATE.

data: begin of CS_EXPTION,

OP_NAME type STRING,

DELEMS type range of ROLLNAME,

INCLUDE type ABAP_BOOL,

EXCLUDE type ABAP_BOOL,

end of CS_EXPTION.

data: CT_EXPTION like hashed table of CS_EXPTION with unique key OP_NAME.

  methods: CTO_INT_TEXT importing I_INPUT type CLIKE

                          returning VALUE(R_OUTPUT) type STRING.

     methods: CONVERT_DATE  importing PI_DATE type CLIKE

                            returning VALUE(PR_CDATE) type STRING.

endclass.                    “LCL_DATA_ROOT DEFINITION

class LCL_DATA_ROOT implementation.

   method CTO_INT_TEXT.

R_OUTPUT = I_INPUT.

condense R_OUTPUT no-gaps.

translate R_OUTPUT to upper case.

endmethod.                    “CTO_INT_TEXT

method CONVERT_DATE.

data: L_DATE type CY_DATE.

L_DATE = PI_DATE.

concatenate L_DATE-D L_DATE-M L_DATE-Y into PR_CDATE separated by ‘.’.

endmethod.                    “CONVERT_DATE

endclass.                    “LCL_DATA_ROOT IMPLEMENTATION

 

 

class LCL_DATA_DESCRIPTION

class LCL_DATA_DESCRIPTION definition inheriting from LCL_DATA_ROOT.

   public section.

data: CA_NAME type STRING.

methods: CONSTRUCTOR importing PI_NAME type STRING.

     methods: SET_TABLE_STRUCTURE

              importing PIT_TAB type any table.

 

     methods: SET_STRUCTURE importing PIS_STRUCT type DATA.

 

     methods: GET_COMPONENTS

          importing PI_OP_NAME type STRING optional

          returning VALUE(PRT_COMPONENTS) type ABAP_COMPONENT_TAB.

 

     methods: ADD_EXPTION

              importing PI_OP_NAME type STRING

                        PI_DELEM type ROLLNAME

                        PI_INCLUDE type ABAP_BOOL default ABAP_FALSE

                        PI_EXCLUDE type ABAP_BOOL default ABAP_FALSE.

 

private section.

type-pools: ABAP.

data: CO_TDESCR type ref to CL_ABAP_TABLEDESCR,

CO_TL_SDESCR type ref to CL_ABAP_STRUCTDESCR.

endclass.                    “LCL_DATA_DESCRIPTION DEFINITION

class LCL_DATA_DESCRIPTION implementation.

method GET_COMPONENTS.

data: L_OP_NAME type STRING.

data: LT_COMPONENTS type standard table of ABAP_COMPONENTDESCR,

LT_TCOMP type standard table of ABAP_COMPONENTDESCR.

data: LO_SDESCR type ref to CL_ABAP_STRUCTDESCR.

field-symbols: <LFS_COMPONENT&gt; type ABAP_COMPONENTDESCR.

field-symbols: <LFS_EXCPTION&gt; like line of CT_EXPTION.

LT_COMPONENTS = CO_TL_SDESCR-&gt;GET_COMPONENTS( ).

loop at LT_COMPONENTS assigning <LFS_COMPONENT&gt;

where AS_INCLUDE eq ABAP_TRUE.

LO_SDESCR ?= <LFS_COMPONENT&gt;-TYPE.

LT_TCOMP = LO_SDESCR-&gt;GET_COMPONENTS( ).

insert lines of LT_TCOMP into table PRT_COMPONENTS.

clear: LT_TCOMP, LO_SDESCR.

endloop.

if SY-SUBRC ne 0.

PRT_COMPONENTS = LT_COMPONENTS.

endif.

if PI_OP_NAME is supplied.

L_OP_NAME = ME-&gt;CTO_INT_TEXT( PI_OP_NAME  ).

loop at CT_EXPTION assigning <LFS_EXCPTION&gt;

where OP_NAME eq L_OP_NAME.

if <LFS_EXCPTION&gt;-INCLUDE eq ABAP_TRUE.

delete PRT_COMPONENTS where NAME not in <LFS_EXCPTION&gt;-DELEMS.

endif.

if <LFS_EXCPTION&gt;-EXCLUDE eq ABAP_TRUE.

delete PRT_COMPONENTS where NAME in <LFS_EXCPTION&gt;-DELEMS.

endif.

endloop.

endif.

   endmethod.                    “GET_COMPONENTS

method CONSTRUCTOR.

SUPER->CONSTRUCTOR( ).

CA_NAME = PI_NAME.

endmethod.                    “constructor

method SET_TABLE_STRUCTURE.

CO_TDESCR ?= CL_ABAP_TYPEDESCR=&gt;DESCRIBE_BY_DATA( PIT_TAB ).

CO_TL_SDESCR ?= CO_TDESCR-&gt;GET_TABLE_LINE_TYPE( ).

endmethod.                    “set_table_structure

 

method SET_STRUCTURE.

CO_TL_SDESCR ?= CL_ABAP_TYPEDESCR=&gt;DESCRIBE_BY_DATA( PIS_STRUCT ).

endmethod.                    “set_structure

 

method ADD_EXPTION.

data: LS_EXPTION like CS_EXPTION.

data: L_NAME type STRING.

data: L_DELEM type STRING.

data LRS_DELEM like line of CS_EXPTION-DELEMS.

field-symbols <LFS_EXPTION&gt; like CS_EXPTION.

L_NAME = PI_OP_NAME.

L_DELEM = PI_DELEM.

condense L_DELEM no-gaps.

translate L_DELEM to upper case.

condense L_NAME no-gaps.

translate L_NAME to upper case.

LRS_DELEM-SIGN = ‘I’.

LRS_DELEM-OPTION = ‘EQ’.

LRS_DELEM-LOW = L_DELEM.

read table CT_EXPTION with key OP_NAME = L_NAME assigning <LFS_EXPTION&gt;.

if SY-SUBRC eq 0.

append LRS_DELEM to <LFS_EXPTION&gt;-DELEMS.

else.

LS_EXPTION-OP_NAME = L_NAME.

LS_EXPTION-include = PI_INCLUDE.

LS_EXPTION-exclude = PI_exclude.

append LRS_DELEM to LS_EXPTION-DELEMS.

insert LS_EXPTION into table CT_EXPTION.

endif.

endmethod.                    “add_exption

endclass.                    “lcl_data_description IMPLEMENTATION

 

class LCL_DATA_UTIL

 

class LCL_DATA_UTIL definition inheriting from LCL_DATA_ROOT.

   public section.

    classmethods: GET_INSTANCE returning VALUE(RO_INSTANCE) type ref to LCL_DATA_UTIL.

   methods SET_TAB_DESCR

        importing PIT_TAB type any table

                        PI_NAME type STRING.

 

methods SET_STRUCT_DESCR

         importing PIS_STRUCT type DATA

                   PI_NAME type STRING.

methods GET_DDESCR

         importing PI_NAME type STRING

         returning VALUE(PRO_DESCR) type ref to LCL_DATA_DESCRIPTION.

private section.

data: begin of CS_DESCR,

NAME type STRING,

DESCR type ref to LCL_DATA_DESCRIPTION,

end of CS_DESCR.

data: CT_DESCR like standard table of CS_DESCR.

classdata: CO_INSTANCE type ref to LCL_DATA_UTIL.

endclass.                    “LCL_DATA_UTIL DEFINITION

 

class LCL_DATA_UTIL implementation.

  method SET_STRUCT_DESCR.

data: LS_DESCR like CS_DESCR.

data: LO_DDESCR type ref to LCL_DATA_DESCRIPTION.

LS_DESCR-NAME = PI_NAME.

condense LS_DESCR-NAME no-gaps.

translate LS_DESCR-NAME to upper case.

create object LO_DDESCR

exporting

PI_NAME = LS_DESCR-NAME.

LO_DDESCR-&gt;SET_STRUCTURE( PIS_STRUCT ).

LS_DESCR-DESCR = LO_DDESCR.

append LS_DESCR to CT_DESCR.

   endmethod.                    “SET_TAB_DESCR

method SET_TAB_DESCR.

data: LS_DESCR like CS_DESCR.

data: LO_DDESCR type ref to LCL_DATA_DESCRIPTION.

LS_DESCR-NAME = PI_NAME.

condense LS_DESCR-NAME no-gaps.

translate LS_DESCR-NAME to upper case.

read table CT_DESCR with key NAME = LS_DESCR-NAME transporting no fields.

if SY-SUBRC ne 0.

create object LO_DDESCR

exporting

PI_NAME = LS_DESCR-NAME.

LO_DDESCR-&gt;SET_TABLE_STRUCTURE( PIT_TAB ).

LS_DESCR-DESCR = LO_DDESCR.

append LS_DESCR to CT_DESCR.

endif.

endmethod.                    “SET_TAB_DESCR

 

method GET_DDESCR.

data: L_NAME type STRING.

field-symbols: <LFS_DESCR&gt; like CS_DESCR.

L_NAME = ME-&gt;CTO_INT_TEXT( PI_NAME ).

loop at CT_DESCR assigning <LFS_DESCR&gt;

where NAME eq L_NAME.

PRO_DESCR = <LFS_DESCR&gt;-DESCR.

endloop.

   endmethod.                    “get_ddescr

   method GET_INSTANCE.

if CO_INSTANCE is bound.

RO_INSTANCE = CO_INSTANCE.

else.

create object CO_INSTANCE.

RO_INSTANCE = CO_INSTANCE.

endif.

   endmethod.                    “GET_INSTANCE

endclass.                    “LCL_DATA_UTIL IMPLEMENTATION

class  LCL_STRUCT_UTIL

class LCL_STRUCT_UTIL definition inheriting from LCL_DATA_ROOT.

  public section.

classmethods: GET_INSTANCE returning VALUE(RO_INSTANCE) type ref to LCL_STRUCT_UTIL.

 

   methods MOVE_CORR

             importing PIS_FROM type DATA

                       PI_SNAME type STRING

             changing  PCS_TO type DATA.

   methods ADD_CORR

             importing PIS_FROM type DATA

                             PI_SNAME type STRING

             changing  PCS_TO type DATA.

methods CONVERT_TO_TEXT

             importing PIS_FROM type DATA

                       PI_SNAME type STRING

                       PI_SEPERATOR type C default CL_ABAP_CHAR_UTILITIES=&gt;HORIZONTAL_TAB

             returning VALUE(R_STRING) type STRING.

private section.

classdata: CO_INSTANCE type ref to LCL_STRUCT_UTIL.

data: CO_DUTIL type ref to LCL_DATA_UTIL.

data: CO_DESCR type ref to LCL_DATA_DESCRIPTION.

endclass.                    “LCL_DATA_UTIL DEFINITION

 

class LCL_STRUCT_UTIL implementation.

method MOVE_CORR.

data: L_NAME type STRING.

data: LT_COMPONENTS type ABAP_COMPONENT_TAB.

field-symbols: <LFS_COMPONENT&gt;  type line of ABAP_COMPONENT_TAB,

<LFS_FFIELD&gt; type ANY,

<LFS_TFIELD&gt; type ANY.

L_NAME = ME-&gt;CTO_INT_TEXT( PI_SNAME ).

CO_DUTIL = LCL_DATA_UTIL=&gt;GET_INSTANCE( ).

CO_DESCR = CO_DUTIL-&gt;GET_DDESCR( L_NAME ).

LT_COMPONENTS = CO_DESCR-&gt;GET_COMPONENTS( ‘MOVE_C’ ).

loop at LT_COMPONENTS assigning <LFS_COMPONENT&gt;.

assign component <LFS_COMPONENT&gt;-NAME  of structure PIS_FROM

to <LFS_FFIELD&gt; casting type handle <LFS_COMPONENT&gt;-TYPE.

check <LFS_FFIELD&gt; is assigned.

assign component <LFS_COMPONENT&gt;-NAME  of structure PCS_TO

to <LFS_TFIELD&gt; casting type handle <LFS_COMPONENT&gt;-TYPE.

check <LFS_TFIELD&gt; is assigned.

<LFS_TFIELD&gt; = <LFS_FFIELD&gt;.

unassign: <LFS_TFIELD&gt; , <LFS_FFIELD&gt;.

endloop.

   endmethod.                    “move_corr

method ADD_CORR.

data: L_NAME type STRING.

data: LT_COMPONENTS type ABAP_COMPONENT_TAB.

field-symbols: <LFS_COMPONENT&gt;  type line of ABAP_COMPONENT_TAB,

<LFS_FFIELD&gt; type ANY,

<LFS_TFIELD&gt; type ANY.

L_NAME = ME-&gt;CTO_INT_TEXT( PI_SNAME ).

CO_DUTIL = LCL_DATA_UTIL=&gt;GET_INSTANCE( ).

CO_DESCR = CO_DUTIL-&gt;GET_DDESCR( L_NAME ).

LT_COMPONENTS = CO_DESCR-&gt;GET_COMPONENTS( ‘ADD_C’ ).

loop at LT_COMPONENTS assigning <LFS_COMPONENT&gt;.

check <LFS_COMPONENT&gt;-TYPE->TYPE_KIND ca ‘IFP’.

assign component <LFS_COMPONENT&gt;-NAME  of structure PIS_FROM

to <LFS_FFIELD&gt; casting type handle <LFS_COMPONENT&gt;-TYPE.

check <LFS_FFIELD&gt; is assigned.

assign component <LFS_COMPONENT&gt;-NAME  of structure PCS_TO

to <LFS_TFIELD&gt; casting type handle <LFS_COMPONENT&gt;-TYPE.

check <LFS_TFIELD&gt; is assigned.

add <LFS_FFIELD&gt; to <LFS_TFIELD&gt;.

unassign: <LFS_TFIELD&gt; , <LFS_FFIELD&gt;.

endloop.

endmethod.                    “add_corr

 

method CONVERT_TO_TEXT.

data: L_NAME type STRING.

data: L_VAL  type STRING.

data: LT_COMPONENTS type ABAP_COMPONENT_TAB.

field-symbols: <LFS_COMPONENT&gt;  type line of ABAP_COMPONENT_TAB,

<LFS_FFIELD&gt; type ANY,

<LFS_TFIELD&gt; type ANY.

L_NAME = ME-&gt;CTO_INT_TEXT( PI_SNAME ).

CO_DUTIL = LCL_DATA_UTIL=&gt;GET_INSTANCE( ).

CO_DESCR = CO_DUTIL-&gt;GET_DDESCR( L_NAME ).

LT_COMPONENTS = CO_DESCR-&gt;GET_COMPONENTS( ‘CT_TEXT’ ).

loop at LT_COMPONENTS assigning <LFS_COMPONENT&gt;.

assign component <LFS_COMPONENT&gt;-NAME  of structure PIS_FROM

to <LFS_FFIELD&gt; casting type handle <LFS_COMPONENT&gt;-TYPE.

check <LFS_FFIELD&gt; is assigned.

L_VAL = <LFS_FFIELD&gt;.

concatenate L_VAL PI_SEPERATOR into L_VAL.

concatenate R_STRING L_VAL into R_STRING.

unassign: <LFS_FFIELD&gt;.

endloop.

endmethod.                    “CONVERT_TO_TEXT

 

   method GET_INSTANCE.

if CO_INSTANCE is bound.

RO_INSTANCE = CO_INSTANCE.

else.

create object CO_INSTANCE.

RO_INSTANCE = CO_INSTANCE.

endif.

   endmethod.                    “GET_INSTANCE

endclass.

 

class LCL_EXCEL_BASE  

 

class LCL_EXCEL_BASE definition.

   public section.

include OLE2INCL.

types: begin of Y_RANGE,

PARENT type STRING,

NAME type STRING,

TOP type I,

LEFT type I,

WIDTH type I,

DEPTH type I,

OBJECT type ref to LCL_RANGE,

end of Y_RANGE.

data: T_RANGES type standard table of Y_RANGE.

* App methods

   methods: INITIALIZE importing I_FILE type RCGFILETR-FTFRONT optional.

     methods: CLEAR.

     methods: SHOW.

 

protected section.

data:  FILE_FRONT_END type RCGFILETR-FTFRONT,

FULLPATH_APPL  type RCGFILETR-FTAPPL,

TEMPPATH_APPL  type STRING.

data: O_APPLICATION type OLE2_OBJECT,

O_WORKBOOK    type OLE2_OBJECT,

*          O_ACTIVE_BOOK type OLE2_OBJECT,

O_SHEET       type OLE2_OBJECT.

endclass.                    “LCL_EXCEL_BASE DEFINITION

class LCL_EXCEL_BASE implementation.

   method INITIALIZE.

create object O_APPLICATION ‘excel.Application’ no flush.

call method of

O_APPLICATION

‘WorkBooks’   = O_WORKBOOK.

if not I_FILE is supplied.

call method of

O_WORKBOOK

‘ADD’.

else.

call method of

O_WORKBOOK

‘OPEN’

exporting

#1         = I_FILE.

if SY-SUBRC <&gt; 0.

message ‘File not found’ type ‘E’.

endif.

endif.

call method of

O_APPLICATION

‘WorkSheets’  = O_SHEET

no

flush

exporting

#1            = 1.

call method of

O_SHEET

‘SELECT’.

endmethod.                    “initialize

method CLEAR.

field-symbols: <LFS_RANGE&gt; type Y_RANGE.

loop at T_RANGES assigning <LFS_RANGE&gt;.

<LFS_RANGE&gt;-OBJECT-&gt;FREE( ).

endloop.

clear: T_RANGES.

free object O_SHEET.

free object O_WORKBOOK.

free object O_APPLICATION.

endmethod.                    “CLEAR

method SHOW.

set property of O_APPLICATION ‘Visible’ = 1.

endmethod.                    “SHOW

endclass.                    “LCL_ExCEL_base IMPLEMENTATION

 

class LCL_EXCEL

 

class LCL_EXCEL definition inheriting from LCL_EXCEL_BASE.

   public section.

   methods: PREP_RANGE

       importing

           I_PARENT type STRING optional

           I_NAME type STRING

           I_TOP type I optional

           I_LEFT type I optional

           I_WIDTH type I default 1

           I_DEPTH type I default 1

           I_SNAME type STRING optional

           returning VALUE(R_RANGE) type ref to LCL_RANGE.

methods: GET_ITEM

        importing

          I_FROM type ref to LCL_RANGE_BASE

          I_NUMBER type I

          I_WIDTH type I default 1

          I_DEPTH type I default 1

          returning VALUE(R_RANGE) type ref to LCL_RANGE.

methods: GET_ROW

      importing

          I_FROM type ref to LCL_RANGE_BASE

          I_NUMBER type I

          I_SNAME type STRING optional

          returning VALUE(R_RANGE) type ref to LCL_RANGE.

methods: GET_COLUMN

      importing

          I_FROM type ref to LCL_RANGE_BASE

          I_NUMBER type I

          I_SNAME type STRING optional

          returning VALUE(R_RANGE) type ref to LCL_RANGE.

methods: SUB_RANGE

       importing

          I_FROM type ref to LCL_RANGE_BASE

          I_PARENT type STRING optional

          I_NAME type STRING OPTIONAL

          I_TOP type I optional

          I_LEFT type I optional

          I_WIDTH type I default 1

          I_DEPTH type I default 1

          I_SNAME type STRING optional

          returning VALUE(R_RANGE) type ref to LCL_RANGE.

methods: RT_OFF importing

          I_FROM type ref to LCL_RANGE_BASE

          I_PARENT type STRING optional

          I_NAME type STRING OPTIONAL

          I_TOP type I optional

          I_LEFT type I optional

          I_WIDTH type I default 1

          I_DEPTH type I default 1

          I_SNAME type STRING optional

          returning VALUE(R_RANGE) type ref to LCL_RANGE.

methods: LB_OFF importing

         I_FROM type ref to LCL_RANGE_BASE

         I_PARENT type STRING optional

         I_NAME type STRING OPTIONAL

         I_TOP type I optional

         I_LEFT type I optional

         I_WIDTH type I default 1

         I_DEPTH type I default 1

         I_SNAME type STRING optional

         returning VALUE(R_RANGE) type ref to LCL_RANGE.

methods: GET_RANGE

        importing I_NAME type STRING

                  I_PARENT type STRING optional

        preferred parameter I_NAME

        returning VALUE(R_RANGE) type ref to LCL_RANGE.

endclass.                    “LCL_EXCEL DEFINITION

 

class LCL_EXCEL implementation.

   method PREP_RANGE.

data: LS_RANGE type Y_RANGE.

LS_RANGE-NAME = I_NAME.

LS_RANGE-PARENT = I_PARENT.

LS_RANGE-TOP = I_TOP.

LS_RANGE-LEFT = I_LEFT.

LS_RANGE-WIDTH = I_WIDTH.

LS_RANGE-DEPTH = I_DEPTH.

create object LS_RANGE-OBJECT

exporting

I_PARENT  = LS_RANGE-PARENT

I_NAME    = LS_RANGE-NAME

I_TOP     = LS_RANGE-TOP

I_LEFT    = LS_RANGE-LEFT

I_WIDTH   = LS_RANGE-WIDTH

I_DEPTH   = LS_RANGE-DEPTH

I_SNAME   = I_SNAME

IO_PARENT = O_SHEET.

R_RANGE = LS_RANGE-OBJECT.

check LS_RANGE-NAME is not initial.

append LS_RANGE to T_RANGES.

   endmethod.                    “prep_range

method GET_ITEM.

data: L_TOP type I,

L_LEFT type I,

L_DEPTH type I,

L_WIDTH type I.

data: L_NAME type STRING.

data: L_PARENT type STRING.

data: L_NUMBER(2) type N.

if I_NUMBER gt 0 and I_FROM is bound.

L_DEPTH = I_DEPTH.

L_WIDTH = I_WIDTH.

concatenate I_FROM->PARENT I_FROM->NAME into L_PARENT separated by ‘:’.

if I_NUMBER eq 1.

L_NUMBER = I_NUMBER.

concatenate ‘ITEM’ L_NUMBER into L_NAME.

R_RANGE = ME->SUB_RANGE(

I_FROM = I_FROM

I_PARENT = L_PARENT

I_NAME = L_NAME

I_WIDTH = L_WIDTH

I_DEPTH = L_DEPTH

).

elseif I_NUMBER gt 1.

L_NUMBER = I_NUMBER – 1.

concatenate ‘ITEM’ L_NUMBER into L_NAME.

R_RANGE = ME->GET_RANGE(

I_PARENT = L_PARENT

I_NAME = L_NAME ).

L_NUMBER = I_NUMBER.

concatenate ‘ITEM’ L_NUMBER into L_NAME.

R_RANGE = ME-&gt;RT_OFF(

I_FROM = R_RANGE

I_PARENT = L_PARENT

I_NAME = L_NAME

I_WIDTH = L_WIDTH

I_DEPTH = L_DEPTH

).

endif.

endif.

   endmethod.                    “get_item

  method GET_ROW.

data: L_TOP type I,

L_LEFT type I,

L_DEPTH type I,

L_WIDTH type I.

data: L_NAME type STRING.

data: L_PARENT type STRING.

data: L_NUMBER(2) type N.

if I_NUMBER gt 0 and I_FROM is bound.

L_TOP = I_FROM-&gt;TOP + I_NUMBER – 1.

L_LEFT = I_FROM-&gt;LEFT.

L_WIDTH = I_FROM-&gt;WIDTH.

L_DEPTH = 1.

L_NUMBER = I_NUMBER.

concatenate I_FROM->PARENT I_FROM->NAME into L_PARENT separated by ‘:’.

concatenate ‘ROW’ L_NUMBER into L_NAME.

R_RANGE = ME->PREP_RANGE(

I_PARENT = L_PARENT

I_NAME = L_NAME

I_TOP = L_TOP

I_LEFT = L_LEFT

I_WIDTH = L_WIDTH

I_DEPTH = L_DEPTH

I_SNAME = I_SNAME

).

endif.

   endmethod.                    “GET_ROW

   method GET_COLUMN.

data: L_TOP type I,

L_LEFT type I,

L_DEPTH type I,

L_WIDTH type I.

data: L_NAME type STRING.

data: L_PARENT type STRING.

data: L_NUMBER(2) type N.

field-symbols: <LFS_RANGE&gt; type Y_RANGE.

if I_NUMBER gt 0 and I_FROM is bound.

L_TOP = I_FROM-&gt;TOP.

L_LEFT = I_FROM-&gt;LEFT + I_NUMBER – 1.

L_DEPTH = I_FROM-&gt;DEPTH.

L_WIDTH = 1.

L_NUMBER = I_NUMBER.

concatenate I_FROM->PARENT I_FROM->NAME into L_PARENT separated by ‘:’.

concatenate ‘COLUMN’ L_NUMBER into L_NAME.

R_RANGE = ME->PREP_RANGE(

I_PARENT = L_PARENT

I_NAME = L_NAME

I_TOP = L_TOP

I_LEFT = L_LEFT

I_WIDTH = L_WIDTH

I_DEPTH = L_DEPTH

I_SNAME = I_SNAME

).

endif.

   endmethod.                    “GET_COLUMN

method SUB_RANGE.

data: L_TOP type I,

L_LEFT type I,

L_DEPTH type I,

L_WIDTH type I.

if I_FROM is bound.

L_TOP = I_FROM-&gt;TOP + I_TOP.

L_LEFT = I_FROM-&gt;LEFT + I_LEFT.

L_WIDTH = I_WIDTH.

L_DEPTH = I_DEPTH.

R_RANGE = ME->PREP_RANGE(

I_PARENT = I_PARENT

I_NAME = I_NAME

I_TOP = L_TOP

I_LEFT = L_LEFT

I_WIDTH = L_WIDTH

I_DEPTH = L_DEPTH

I_SNAME = I_SNAME

).

endif.

   endmethod.                    “SUB_RANGE

   method RT_OFF.

data: L_TOP type I,

L_LEFT type I,

L_DEPTH type I,

L_WIDTH type I.

if I_FROM is bound.

L_TOP = I_TOP + I_FROM-&gt;TOP.

L_LEFT = I_LEFT + I_FROM-&gt;LEFT + I_FROM-&gt;WIDTH.

L_DEPTH = I_DEPTH.

L_WIDTH = I_WIDTH.

R_RANGE = ME->PREP_RANGE(

I_PARENT = I_PARENT

I_NAME = I_NAME

I_TOP = L_TOP

I_LEFT = L_LEFT

I_WIDTH = L_WIDTH

I_DEPTH = L_DEPTH

I_SNAME = I_SNAME

).

endif.

   endmethod.                    “RT_OFF

method LB_OFF.

data: L_TOP type I,

L_LEFT type I,

L_DEPTH type I,

L_WIDTH type I.

if I_FROM is bound.

L_TOP = I_TOP + I_FROM-&gt;TOP + I_FROM-&gt;DEPTH.

L_LEFT = I_LEFT + I_FROM-&gt;LEFT.

L_DEPTH = I_DEPTH.

L_WIDTH = I_WIDTH.

R_RANGE = ME->PREP_RANGE(

I_PARENT = I_PARENT

I_NAME = I_NAME

I_TOP = L_TOP

I_LEFT = L_LEFT

I_WIDTH = L_WIDTH

I_DEPTH = L_DEPTH

I_SNAME = I_SNAME

).

endif.

   endmethod.                    “LB_OFF

   method GET_RANGE.

field-symbols: <LFS_RANGE&gt; type Y_RANGE.

loop at T_RANGES assigning <LFS_RANGE&gt;

where NAME eq I_NAME

and PARENT eq I_PARENT.

R_RANGE = <LFS_RANGE&gt;-OBJECT.

endloop.

   endmethod.                    “get_range

endclass.                    “LCL_EXCEL IMPLEMENTATION

 

class LCL_RANGE_DATA

 

class LCL_RANGE_DATA definition.

   public section.

*   underline

constants: C_ULINE type I value 2.

constants: C_DB_ULINE type I value 5.

*   alignment

constants: C_CENTER type I value4108.

constants: C_LEFT type I value4131.

constants: C_RIGHT type I value4152.

constants: C_TOP type I value4160.

constants: C_BOTTOM type I value4107.

*    number formats

constants: C_RATIONAL type STRING value ‘0.00’.

constants: C_CURRENCY type STRING value ‘#,##0.00’.

constants: C_GENERAL type STRING value ‘@’.

constants: C_DATE type STRING value ‘mm/dd/yy’.

constants: C_TIME type STRING value ‘hh:mm:ss’.

constants: C_INT type STRING value ‘0’.

constants: C_IIN type STRING value ‘0000000000000’.

* line style

constants: C_CONTINUOUS type I value 1.

* colour_index

constants: C_BLACK type I value 1.

* border thickness

constants: C_THICK type I value 4.

constants: C_MEDIUM type I value4138.

constants: C_THIN type I value 2.

  protected section.

endclass.                    “LCL_RANGE_DATA DEFINITION

 

class LCL_RANGE_DATA implementation.

endclass.                    “LCL_RANGE_DATA IMPLEMENTATION

 

 

class LCL_RANGE_BASE

 

class LCL_RANGE_BASE definition inheriting from LCL_RANGE_DATA.

   public section.

include OLE2INCL.

data: PARENT type STRING.

data: NAME type STRING.

data: TOP type I.

data: LEFT type I.

data: WIDTH type I.

data: DEPTH type I.

data: O_RANGE type OLE2_OBJECT.

data: SNAME type STRING.

  methods: CONSTRUCTOR importing I_PARENT type STRING optional

                                    I_NAME type STRING

                                    I_TOP type I optional

                                    I_LEFT type I optional

                                    I_WIDTH type I default 1

                                    I_DEPTH type I default 1

                                    I_SNAME type STRING optional

                                    I_COLUMN type I optional

                                    I_ROW type I optional

                                    IO_PARENT type OLE2_OBJECT.

 

    methods FREE.

protected section.

data: O_DUTIL type ref to LCL_DATA_UTIL,

O_SUTIL type ref to LCL_STRUCT_UTIL.

data: O_CELL_TOP type OLE2_OBJECT.

data: O_CELL_BOT type OLE2_OBJECT.

data: O_PARENT type OLE2_OBJECT.

data: O_FONT type OLE2_OBJECT.

data: O_BORDERS type OLE2_OBJECT.

data: O_BORDER type OLE2_OBJECT.

methods: CREATE_RANGE.

methods: GET_CELL

        importing I_ROW type I

                  I_COLUMN type I

        changing  CO_CELL type OLE2_OBJECT.

     methods: GET_RANGE

       importing IO_FIRST_CELL type OLE2_OBJECT

                 IO_SECOND_CELL type OLE2_OBJECT

       changing  CO_RANGE type OLE2_OBJECT.

endclass.                    “LCL_RANGE_BASE DEFINITION

class LCL_RANGE_BASE implementation.

method CONSTRUCTOR.

SUPER->CONSTRUCTOR( ).

if IO_PARENT is not initial.

O_DUTIL = LCL_DATA_UTIL=&gt;GET_INSTANCE( ).

O_SUTIL = LCL_STRUCT_UTIL=&gt;GET_INSTANCE( ).

O_PARENT = IO_PARENT.

NAME = I_NAME.

TOP = I_TOP.

LEFT = I_LEFT.

WIDTH = I_WIDTH.

DEPTH = I_DEPTH.

PARENT = I_PARENT.

if I_SNAME is not initial.

SNAME = I_SNAME.

endif.

ME->CREATE_RANGE( ).

endif.

endmethod.                    “constructor

method GET_CELL.

call method of

O_PARENT

‘cells’  = CO_CELL

no

flush

exporting

#1       = I_ROW

#2       = I_COLUMN.

   endmethod.                    “get_CELL

   method CREATE_RANGE.

data: L_FINAL_ROW type I,

L_FINAL_COLUMN type I.

L_FINAL_ROW = TOP + DEPTH – 1.

L_FINAL_COLUMN = LEFT + WIDTH – 1.

ME->GET_CELL(

exporting I_ROW = TOP

I_COLUMN = LEFT

changing  CO_CELL = O_CELL_TOP ).

ME->GET_CELL(

exporting I_ROW = L_FINAL_ROW

I_COLUMN = L_FINAL_COLUMN

changing  CO_CELL = O_CELL_BOT ).

ME->GET_RANGE(

exporting IO_FIRST_CELL = O_CELL_TOP

IO_SECOND_CELL = O_CELL_BOT

changing  CO_RANGE = O_RANGE ).

   endmethod.                    “create_range

method GET_RANGE.

call method of

O_PARENT

‘RANGE’  = CO_RANGE

no

flush

exporting

#1       = IO_FIRST_CELL

#2       = IO_SECOND_CELL.

   endmethod.                    “GET_RANGE

 

   method FREE.

free object O_BORDER no flush.

free object O_BORDERS no flush.

free object O_FONT no flush.

free object O_CELL_TOP no flush.

free object O_CELL_BOT no flush.

free object O_RANGE no flush.

   endmethod.                    “FREE

endclass.                    “LCL_RANGE_BASE IMPLEMENTATION

class LCL_RANGE

class LCL_RANGE definition inheriting from LCL_RANGE_BASE.

   public section.

methods: CONSTRUCTOR importing I_PARENT type STRING optional

                                    I_NAME type STRING

                                    I_TOP type I optional

                                    I_LEFT type I optional

                                    I_WIDTH type I default 1

                                    I_DEPTH type I default 1

                                    I_SNAME type STRING optional

                                    IO_PARENT type OLE2_OBJECT.

methods: MERGE.

     methods: INSERT_VALUE importing I_TEXT type DATA optional

                                     IT_TEXTS type standard table  optional

                                     I_SEPTXT type ABAP_BOOL default ABAP_FALSE

                           preferred parameter I_TEXT.

   methods: SET_FONT

            importing

              I_FNAME  type STRING optional

              I_FSIZE  type I optional

              I_FCOLOUR type I optional

              preferred parameter I_FSIZE.

 

methods: BOLD importing I_FLAG type ABAP_BOOL default ABAP_TRUE.

     methods: ITALIC importing I_FLAG type ABAP_BOOL default ABAP_TRUE.

 

     methods: ULINE importing I_FLAG type ABAP_BOOL default ABAP_TRUE.

 

     methods: DULINE importing I_FLAG type ABAP_BOOL default ABAP_TRUE.

 

     methods: SET_ALIGN importing  I_ALIGN type I.

 

     methods: SET_VALIGN importing  I_ALIGN type I.

 

     methods: SET_WIDTH importing I_VALUE type I.

 

     methods: SET_HEIGHT importing I_VALUE type I.

 

     methods: SHRINK_TF importing I_FLAG type ABAP_BOOL default ABAP_TRUE.

 

     methods: AUTOFIT importing I_FLAG type ABAP_BOOL default ABAP_TRUE.

 

     methods: WRAP_TEXT importing I_FLAG type ABAP_BOOL default ABAP_TRUE.

 

     methods: PASTE_TABLE importing IT_DATA type any table.

 

     methods: PASTE_STRUC importing I_STRUC type DATA.

 

     methods: SET_NFORMAT importing I_NFORMAT type STRING.

 

     methods: SET_BORDER

       importing I_WEIGHT type I default C_THIN

                 I_BAROUND type ABAP_BOOL default ABAP_FALSE

                 preferred parameter I_WEIGHT.

endclass.                    “LCL_range DEFINITION

class LCL_RANGE implementation.

method CONSTRUCTOR.

call method SUPER->CONSTRUCTOR

exporting

I_PARENT  = I_PARENT

I_NAME    = I_NAME

I_TOP     = I_TOP

I_LEFT    = I_LEFT

I_WIDTH   = I_WIDTH

I_DEPTH   = I_DEPTH

I_SNAME   = I_SNAME

IO_PARENT = IO_PARENT.

get property of O_RANGE ‘Font’  = O_FONT no flush.

get property of O_RANGE ‘Borders’ = O_BORDERS no flush.

endmethod.                    “constructor

method INSERT_VALUE.

data: L_TEXT type STRING.

data: L_VALUE type STRING.

if I_TEXT is supplied.

L_VALUE = I_TEXT.

elseif IT_TEXTS is supplied.

loop at IT_TEXTS into L_TEXT.

if I_SEPTXT eq ABAP_FALSE.

concatenate L_VALUE L_TEXT into L_VALUE separated by SPACE.

else.

concatenate L_VALUE L_TEXT into L_VALUE separated by CL_ABAP_CHAR_UTILITIES=&gt;NEWLINE.

endif.

endloop.

endif.

if L_VALUE is not initial.

set property of O_RANGE ‘Value’ = L_VALUE no flush.

endif.

endmethod.                    “INSERT_VALUE

 

method MERGE.

call method of

O_RANGE

‘Merge’

no

flush.

endmethod.                    “merge

 

method SET_FONT.

*  Размер шрифта (number between 1 or 72)

*  Цвет шрифта (number between 1 or 56(0-оставить без изменения))

if I_FNAME is supplied.

set property of O_FONT ‘Name’ = I_FNAME no flush.

endif.

if I_FSIZE is supplied.

set property of O_FONT ‘Size’ = I_FSIZE no flush.

endif.

if I_FCOLOUR is supplied” Цвет шрифта

set property of O_FONT ‘ColorIndex’ = I_FCOLOUR no flush.

endif.

endmethod.                    “SET_FONT

 

method BOLD.

if I_FLAG eq ABAP_TRUE.

set property of O_FONT ‘Bold’ = ‘True’ no flush.

else.

set property of O_FONT ‘Bold’ = ‘FALSE’ no flush.

endif.

endmethod.                    “BOLD

 

method ITALIC.

if I_FLAG eq ABAP_TRUE.

set property of O_FONT ‘Italic’ = ‘True’ no flush.

else.

set property of O_FONT ‘Italic’ = ‘FALSE’ no flush.

endif.

  endmethod.                    “ITALIC

 

method ULINE.

if I_FLAG eq ABAP_TRUE.

set property of O_FONT ‘Underline’ = C_ULINE no flush.

endif.

endmethod.                    “ULINE

 

method DULINE.

if I_FLAG eq ABAP_TRUE.

set property of O_FONT ‘Underline’ = C_DB_ULINE no flush.

endif.

endmethod.                    “DULINE

 

method SET_ALIGN.

set property of O_RANGE ‘HorizontalAlignment’ = I_ALIGN no flush.

endmethod.                    “SET_ALIGN

 

method SET_VALIGN.

set property of O_RANGE ‘VerticalAlignment’ = I_ALIGN no flush.

endmethod.                    “SET_ALIGN

 

method SET_WIDTH.

set property of O_RANGE ‘ColumnWidth’ = I_VALUE no flush.

endmethod.                    “SET_WIDTH

 

method SET_HEIGHT.

set property of O_RANGE ‘RowHeight’ = I_VALUE no flush.

endmethod.                    “SET_HEIGHT

 

method SHRINK_TF.

if I_FLAG eq ABAP_TRUE.

set property of O_RANGE ‘ShrinkToFit’ = ‘TRUE’ no flush.

else.

set property of O_RANGE ‘ShrinkToFit’ = ‘FALSE’ no flush.

endif.

endmethod.                    “SHRINK_TF

 

method AUTOFIT.

if I_FLAG eq ABAP_TRUE.

call method of

O_RANGE

‘Autofit’

no

flush.

endif.

endmethod.                    “AUTOFIT

 

method WRAP_TEXT.

if I_FLAG eq ABAP_TRUE.

set property of O_RANGE ‘WrapText’ = ‘TRUE’ no flush.

else.

set property of O_RANGE ‘WrapText’ = ‘FALSE’ no flush.

endif.

endmethod.                    “WRAP_TEXT

method SET_NFORMAT.

set property of O_RANGE ‘NumberFormat’ = I_NFORMAT no flush.

   endmethod.                    “SET_NFORMAT

 

   method SET_BORDER.

if I_BAROUND eq ABAP_TRUE.

call method of

O_RANGE

‘BorderAround’

no

flush

exporting

#1             = C_CONTINUOUS

#2             = I_WEIGHT

#3             = C_BLACK.

else.

set property of O_BORDERS ‘LineStyle’ =  C_CONTINUOUS no flush.

set property of O_BORDERS ‘ColorIndex’ = C_BLACK no flush.

set property of O_BORDERS ‘Weight’ = I_WEIGHT no flush.

endif.

   endmethod.                    “set_border

   method PASTE_TABLE.

data: LS_DATA_LINE(1000) type C.

data: LT_DATA like standard table of LS_DATA_LINE.

data: L_SUBRC like SY-SUBRC.

field-symbols: <LFS_LINE&gt; type DATA.

check IT_DATA  is not initial.

loop at IT_DATA assigning <LFS_LINE&gt;.

LS_DATA_LINE =  O_SUTIL-&gt;CONVERT_TO_TEXT(

PIS_FROM = <LFS_LINE&gt;

PI_SNAME = SNAME

).

append LS_DATA_LINE to LT_DATA.

endloop.

      call function ‘FLUSH’

exceptions

CNTL_SYSTEM_ERROR = 1

CNTL_ERROR        = 2

others            = 3.

call method CL_GUI_FRONTEND_SERVICES=&gt;CLIPBOARD_EXPORT

importing

DATA                 = LT_DATA

changing

RC                   = L_SUBRC

exceptions

CNTL_ERROR           = 1

ERROR_NO_GUI         = 2

NOT_SUPPORTED_BY_GUI = 3

others               = 4.

call method of

O_RANGE

‘Select’

no

flush.

call method of

O_PARENT

‘Paste’ no flush.

endmethod.                    “paste_table

   method PASTE_STRUC.

data: LS_DATA_LINE(1000) type C.

data: LT_DATA like standard table of LS_DATA_LINE.

data: L_SUBRC like SY-SUBRC.

field-symbols: <LFS_LINE&gt; type DATA.

check I_STRUC  is not initial.

LS_DATA_LINE =  O_SUTIL-&gt;CONVERT_TO_TEXT(

PIS_FROM = I_STRUC

PI_SNAME = SNAME

).

append LS_DATA_LINE to LT_DATA.

     call function ‘FLUSH’

exceptions

CNTL_SYSTEM_ERROR = 1

CNTL_ERROR        = 2

others            = 3.

call method CL_GUI_FRONTEND_SERVICES=&gt;CLIPBOARD_EXPORT

importing

DATA                 = LT_DATA

changing

RC                   = L_SUBRC

exceptions

CNTL_ERROR           = 1

ERROR_NO_GUI         = 2

NOT_SUPPORTED_BY_GUI = 3

others               = 4.

call method of

O_RANGE

‘Select’

no

flush.

call method of

O_PARENT

‘Paste’

no

flush.

   endmethod.                    “paste_table

endclass.                    “LCL_range IMPLEMENTATION

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

  1. Tudor Riscutia

    Hello Zhambyl,

    Thanks for taking the time to post this, but how is it any different to Ivan Femia‘s abap2xlsx? Except obviously for being a much more simpler solution.
    I don’t mean this the bad way, I’m just curious to see if you found any improvements or different solutions. And if so, you might consider posting them on GitHub as well.

    Thanks,

    Tudor

    (1) 
    1. Zhambyl Kalshabekov Post author

      Hi Tudor. I made this blog as a reference to myself and my colleagues. Most of the client systems we service are not up to date and its a real hurdle to convince them to install abap2xlsx. My solution is based on OLE, while abap2xlsx is based on xml. My framework doensn’t improve on abap2xlsx on any way. It is for anyone who is stuck with older releases of netweaver.

      (0) 
      1. Tudor Riscutia

        Alright, now I get it 🙂

        One question though, if you use your framework while having Office 2007 installed, will it directly open a .xls file? Even though the default type is .xlsx?

        Thanks for clarifying things!

        Tudor

        (0) 

Leave a Reply