Code: Alles auswählen.
* Excel
data:
excel type ole2_object,
workbook type ole2_object,
h_sheet type ole2_object,
h_zelle type ole2_object.
* Excelanwendung wird geöffnet
perform create_excel_object.
* opening the desired excel workbook
perform open_excel_template.
* fill data
perform print_header.
* fill parameter into new sheet
perform create_parameter_sheet.
* create data sheet
perform create_data_sheet.
if not p_makro is initial.
call method of excel 'RUN' exporting #1 = p_makro.
endif.
perform err_hdl.
* save sheet
get property of excel 'ActiveSheet' = h_sheet.
free object h_sheet.
free object workbook.
get property of excel 'ActiveWorkbook' = workbook.
call method of workbook 'SAVEAS' exporting #1 = s_out
#2 = 1.
perform err_hdl.
* CALL METHOD OF workbook 'CLOSE'.
set property of excel 'VISIBLE' = 1.
* CALL METHOD OF excel 'QUIT'.
****forms****
*---------------------------------------------------------------------*
* FORM create_excel_object *
*---------------------------------------------------------------------*
form create_excel_object.
* opening the excel application
create object excel 'Excel.Application'.
set property of excel 'Visible' = 1.
endform. " create_excel_object
*&---------------------------------------------------------------------*
*& Form open_excel_template
*&---------------------------------------------------------------------*
form open_excel_template.
call method of excel 'Workbooks' = workbook.
* open excel file
call method of workbook 'Open' exporting #1 = s_templ. "temuräre Datei wird erstellt. muss existieren
endform. " open_excel_template
*&---------------------------------------------------------------------*
*& Form print_header
*&---------------------------------------------------------------------*
form print_header.
data: j type i.
* Header
j = 1.
loop at headers.
perform fill_cell using 1 j headers.
j = j + 1.
endloop.
endform. " print_header
*&---------------------------------------------------------------------*
*& Form create_parameter_sheet
*&---------------------------------------------------------------------*
form create_parameter_sheet.
data: zeile type i,
spalte type i,
subrc type i.
field-symbols <field> type any.
* create parameter sheet
call method of excel 'WORKSHEETS' = h_sheet
exporting #1 = 'PARAMETER'.
call method of h_sheet 'ACTIVATE'.
zeile = 1.
spalte = 0.
loop at data.
add 1 to zeile.
clear: spalte.
subrc = 0.
while subrc = 0.
add 1 to spalte.
assign component spalte of structure data to <field>.
subrc = sy-subrc.
if subrc = 0.
perform fill_cell using zeile spalte <field>.
endif.
endwhile.
endloop.
free object h_sheet.
endform. " create_parameter_sheet
*&---------------------------------------------------------------------*
*& Form create_data_sheet
*&---------------------------------------------------------------------*
form create_data_sheet.
call method of excel 'WORKSHEETS' = h_sheet.
data: sheet type ole2_object.
call method of excel 'WORKSHEETS' = h_sheet exporting #1 = 'DATEN'.
* CALL METHOD OF h_sheet 'ACTIVATE'.
* call method of h_sheet 'DELETE'.
* CALL METHOD OF excel 'WORKSHEETS' = h_sheet.
* CALL METHOD OF h_sheet 'ADD'.
* CALL METHOD OF excel 'WORKSHEETS' = h_sheet EXPORTING #1 = 1.
call method of h_sheet 'ACTIVATE'.
set property of h_sheet 'NAME' = 'DATEN'.
endform. " create_data_sheet
*---------------------------------------------------------------------*
* FORM fill_cell *
*---------------------------------------------------------------------*
form fill_cell using i j val.
call method of excel 'Cells' = h_zelle exporting #1 = i #2 = j.
perform err_hdl.
set property of h_zelle 'Value' = val .
perform err_hdl.
endform.
*---------------------------------------------------------------------*
* FORM err_hdl *
*---------------------------------------------------------------------*
form err_hdl.
if sy-subrc <> 0.
write: / 'Fehler bei OLE-Automation:'(010), sy-subrc.
stop.
endif.
endform.
Hast Du dein Programm auch vollständig in funktionierender Form?dimes hat geschrieben:Guck dir mal an, hab hier Programm was mit sowas funktioniert.
Frag mich aber nicht wie... :oops:
weiß auch nicht ganz genau wie es funktionier, aber würd es auch gerne wissen. Wenn´s jemand beantworten kann.Code: Alles auswählen.
* Excel ...