DATA: o_excel TYPE ole2_object.
DATA: o_workbook TYPE ole2_object.
DATA: o_sheet TYPE ole2_object.
START-OF-SELECTION.
TRY.
* Excel starten
CREATE OBJECT o_excel 'Excel.Application'.
IF sy-subrc NE 0.
WRITE : / 'Fehler.'.
ELSE.
* Excel sichtbar
SET PROPERTY OF o_excel 'Visible' = 1.
* Anzahl Sheets setzen
SET PROPERTY OF o_excel 'SheetsInNewWorkbook' = 1.
* Workbook holen
CALL METHOD OF o_excel 'WorkBooks' = o_workbook.
* neues Workbook mit einer Sheet hinzufügen
CALL METHOD OF o_workbook 'Add'.
* 1. Sheet holen
CALL METHOD OF o_excel 'Worksheets' = o_sheet
EXPORTING #1 = 1.
* Sheet aktivieren
CALL METHOD OF o_sheet 'Activate'.
* Sheet benennen
SET PROPERTY OF o_sheet 'Name' = 'Tabelle mit Testwerten'.
...
* MessageDialog für Überschreiben einer bestehenden Datei unterdrücken
SET PROPERTY OF o_excel 'DisplayAlerts' = 0.
* Datei speichern unter ...
CALL METHOD OF o_sheet 'SaveAs'
EXPORTING
#1 = p_fname.
* #2 = 1. " Fileformat
* Alle Messages in Excel wieder zulassen
SET PROPERTY OF o_excel 'DisplayAlerts' = -1.
* Workbook schließen
CALL METHOD OF o_workbook 'Close'.
* Excel schließen
CALL METHOD OF o_excel 'Quit'.
* Objekte freigeben
FREE OBJECT: o_sheet,
o_workbook,
o_excel.
ENDIF.
CATCH cx_root INTO DATA(e_text).
MESSAGE e_text->get_text( ) TYPE 'I'.
ENDTRY.