Code: Alles auswählen.
FREE OBJECT: h_mapl,
cell_in,
cell_out,
h_excel.
Code: Alles auswählen.
FREE OBJECT: h_mapl,
cell_in,
cell_out,
h_excel.
Code: Alles auswählen.
CALL METHOD OF h_excel 'Open' = h_open.
FREE OBJECT h_open.
Code: Alles auswählen.
REPORT ztestole NO STANDARD PAGE HEADING.
PARAMETERS: MERKMAL(12) TYPE P DECIMALS 2.
* Excel-Sheet
DATA: VAR_FILE(30) VALUE 'H:\GROUP\OD\ORG\Test_OLE.xls'.
* result
data: result(250).
INCLUDE ole2incl.
* handles for OLE objects
DATA: EXCEL TYPE OLE2_OBJECT, " Excel object
WORKBOOKS TYPE OLE2_OBJECT, " list of workbooks
ACTIVE_WINDOW TYPE OLE2_OBJECT, " active window
CELL_OUT TYPE OLE2_OBJECT, " cell
CELL_IN TYPE OLE2_OBJECT. " cell.
*-----------------------------------------------------------------------
* create instance...
CREATE OBJECT EXCEL 'EXCEL.APPLICATION'.
* set invisible
SET PROPERTY OF EXCEL 'Visible' = 0.
*-----------------------------------------------------------------------
* open existing file
CALL METHOD OF EXCEL 'Workbooks' = WORKBOOKS.
CALL METHOD OF WORKBOOKS 'OPEN' EXPORTING #1 = VAR_FILE.
*-----------------------------------------------------------------------
* get cell (output)
CALL METHOD OF EXCEL 'Cells' = CELL_OUT
EXPORTING #1 = 4 "Zeile
#2 = 1. "Spalte
* set value od cell
SET PROPERTY OF CELL_OUT 'Value' = MERKMAL.
*-----------------------------------------------------------------------
* get cell (input)
CALL METHOD OF EXCEL 'Cells' = CELL_IN
EXPORTING #1 = 4 "Zeile
#2 = 3. "Spalte
* get value of cell
GET PROPERTY OF cell_in 'Value' = result.
*-----------------------------------------------------------------------
* see http://support.microsoft.com/default.aspx?scid=kb;de;503541
* Close without saving
* get active window
CALL METHOD OF EXCEL 'ACTIVEWINDOW' = ACTIVE_WINDOW.
* set active_window visible
SET PROPERTY OF ACTIVE_WINDOW 'VISIBLE' = 1.
*-----------------------------------------------------------------------
* close active_window without saving
CALL METHOD OF ACTIVE_WINDOW 'CLOSE'
EXPORTING #1 = 0.
* close Excel
CALL METHOD OF EXCEL 'QUIT'.
*-----------------------------------------------------------------------
* disconnect from Excel
FREE OBJECT: WORKBOOKS,
CELL_IN,
CELL_OUT,
ACTIVE_WINDOW,
EXCEL.
WRITE RESULT.