Sample program to open excel sheet using OLE

Output:-
 

Code:-

 REPORT zole_demo.
TYPE-POOLS ole2.

DATA: excel TYPE ole2_object,

workbooks TYPE ole2_object,

workbook TYPE ole2_object.

DATA: filename LIKE rlgrap-filename.

*Create object of excel

CREATE OBJECT excel 'excel.application'.

PERFORM err_hand.

*Set property visible = 1 else excel will not be shown

SET PROPERTY OF excel 'VISIBLE' = 1.

PERFORM err_hand.

*Display progress indicator in current window

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

PERCENTAGE = 0

TEXT = 'This process indicates '.

*method to display workbook

call method of excel 'WORKBOOKS' = workbooks.

PERFORM err_hand.

*method to add sheets in workbook

call method of workbooks 'ADD' = workbook.

PERFORM err_hand.

*name of the excel.

CONCATENATE SY-REPID '' SY-DATUM+6(2) '' SY-DATUM+4(2) '_'

SY-DATUM(4) '_' SY-UZEIT '.XLS' INTO FILENAME.

*set the name of the workbook in the save as dialog box

.CALL METHOD OF WORKBOOK 'SAVEAS' EXPORTING #1 = FILENAME.
*&---------------------------------------------------------------------*

*& Form err_hand

*&---------------------------------------------------------------------*

* text

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

FORM err_hand.

*return message in case of error.

IF SY-SUBRC <> 0.

WRITE: / 'OLE ERROR: RETURN CODE ='(I10), SY-SUBRC.

STOP.

ENDIF.

ENDFORM. "err_hand

Labels

ole ole Delete
tutorial tutorial Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.