Code: Alles auswählen.
REPORT zexcel.
INCLUDE ole2incl.
INCLUDE docsincl.
DATA: h_excel TYPE ole2_object,
h_mapl TYPE ole2_object,
h_sheet TYPE ole2_object,
i_file TYPE c LENGTH 128,
cell_out TYPE ole2_object, " cell
cell_in TYPE ole2_object, " cell
h_active_window TYPE ole2_object.
i_file ='\\s2gssa12\d$\migration\verver\Blanko.xls'.
* Excel-Prozess starten
CREATE OBJECT h_excel 'EXCEL.APPLICATION'.
SET PROPERTY OF h_excel 'Visible' = 1. "0 für unsichtbar
CALL METHOD OF h_excel 'Workbooks' = h_mapl.
CALL METHOD OF h_mapl 'OPEN'
EXPORTING
#1 = i_file.
*** In Tabelle schreiben:
*-----------------------------------------------------------
* 1. Zelle, an die Wert übergeben wird (A1)
CALL METHOD OF h_excel 'Cells' = cell_out
EXPORTING
#1 = 6 "Zeile
#2 = 4. "Spalte
* Zellinhalt A1 setzen
SET PROPERTY OF cell_out 'Value' = 'Blah'.
*** Excel schließen
* get active window
CALL METHOD OF h_excel 'ACTIVEWINDOW' = h_active_window.
* set active_window visible
SET PROPERTY OF h_active_window 'VISIBLE' = 1.
** Speichern?
CALL METHOD OF h_mapl 'SaveAs' EXPORTING #1 = 'c:\temp\aaa.xls'.
CALL METHOD OF h_excel 'SaveAs' EXPORTING #1 = 'c:\temp\aaaa.xls'.
* close active_window without saving
CALL METHOD OF h_active_window 'CLOSE'
EXPORTING #1 = 0.
* close Excel
CALL METHOD OF h_excel 'QUIT'.
* Excel-Prozess beenden
FREE OBJECT h_excel.
WRITE 'fertig'.