Hallo Steff,
inzwischen klappt auch das Positionieren(hier muss man nur die obere linke Zelle selektieren.(ging schon am Freitag 09.01.2009)
Erzeuge ich jedoch innerhalb eines Loops mehrere Bilder, wird beim Aufruf des nächsten Bildes die Höhe des vorherigen Bildes verkleinert;
beim Aufruf des dritten Bildes werden die ersten beiden Bilder in Spalte A verschoben und in der Breite verändert.
REPORT z_bebilderte_angebotsanlage_ne
MESSAGE-ID zz
LINE-SIZE 132
LINE-COUNT 65.
************************************************************************
*
* Programmbeschreibung:
*
* Dieses Prog. dient dem Erzeugen einer Excel-Tabelle
*
*
* erstellt von: KaOestreich
*
* geändert am : xx.xx.xx
*
* Achtung:
* Parameter: DMS_MAX_TMP_FILES muss hochgesetzt sein beim User
************************************************************************
TYPE-POOLS ole2.
DATA: excel TYPE ole2_object,
* mapl TYPE ole2_object, " list of workbooks
workbook TYPE ole2_object, " Workbook
* format TYPE ole2_object,
map TYPE ole2_object, " Mappe
* xlalign TYPE ole2_object,
o_cells TYPE ole2_object,
o_sheet TYPE ole2_object,
o_start TYPE ole2_object,
* o_range TYPE ole2_object,
o_end TYPE ole2_object,
o_selection TYPE ole2_object,
o_column TYPE ole2_object,
o_int TYPE ole2_object, "Interior.
o_zelle TYPE ole2_object,
pictures TYPE ole2_object.
DATA: spalte TYPE i VALUE 2.
DATA: zeile TYPE i VALUE 1.
DATA: max_spalte TYPE i VALUE 10.
DATA: max_zeile TYPE i VALUE 5.
DATA: "h_zl1 TYPE ole2_object,
wa_vbak LIKE vbak,
wa_vbap LIKE vbap,
it_vbap LIKE TABLE OF wa_vbap,
files2 LIKE bapi_doc_files2 OCCURS 0 WITH HEADER LINE,
text(255),
*text type string,
BEGIN OF t_item OCCURS 0,
posnr TYPE posnr,
matnr TYPE matnr,
mtextd(40) TYPE c,
mtexte(40) TYPE c,
menge(6) TYPE p,
meins TYPE meins,
netpr(6) TYPE p DECIMALS 2,
waers TYPE waers,
END OF t_item.
*CONSTANTS: xlright TYPE i VALUE '-4102'.
PARAMETERS: pa_angeb LIKE vbak-vbeln DEFAULT '8023873'.
START-OF-SELECTION.
break kaoestreich.
SELECT SINGLE * FROM vbak INTO wa_vbak
WHERE vbeln EQ pa_angeb.
IF sy-subrc IS INITIAL.
ELSE.
MESSAGE e010(ad) WITH 'Angebot existiert nicht.'. "#EC NOTEXT
ENDIF.
CREATE OBJECT excel 'EXCEL.APPLICATION'.
IF sy-subrc NE 0.
WRITE : / 'Fehler CREATE OBJECT'. "#EC NOTEXT
ELSE.
SET PROPERTY OF excel 'Visible' = 1. "0 nicht sichtbar
CALL METHOD OF excel 'Workbooks' = workbook.
CALL METHOD OF workbook 'Add' = map.
* Zeilen farblich hinterlegen
WHILE zeile < max_zeile.
WHILE spalte < max_spalte.
CALL METHOD OF excel 'Cells' = o_zelle
EXPORTING #1 = zeile #2 = spalte.
GET PROPERTY OF o_zelle 'Interior' = o_int.
SET PROPERTY OF o_int 'ColorIndex' = '6'. "Gelb
IF spalte < max_spalte.
ADD 1 TO spalte.
ELSE.
ADD max_spalte TO spalte.
ENDIF.
ENDWHILE.
spalte = 2.
IF zeile EQ 1.
ADD 2 TO zeile.
ELSEIF zeile EQ 3.
ADD 1 TO zeile.
ELSE.
ADD max_zeile TO zeile.
ENDIF.
ENDWHILE.
* Ende Zeilen färben
* Zellen verbinden
CALL METHOD OF excel 'Cells' = o_cells.
CALL METHOD OF o_cells 'Select'.
CALL METHOD OF excel 'ActiveSheet' = o_sheet.
* Range definieren: Start
CALL METHOD OF excel 'Cells' = o_start
EXPORTING
#1 = 1
#1 = 2.
* Range definieren: Ende
CALL METHOD OF excel 'Cells' = o_end
EXPORTING
#1 = 1
#1 = 10.
* Range aktivieren
CALL METHOD OF excel 'range' = o_sheet
EXPORTING
#1 = o_start
#1 = o_end.
* Range selektieren
CALL METHOD OF o_sheet 'Select'.
* Aktuelle Selektion zuweisen
CALL METHOD OF excel 'Selektion' = o_selection.
GET PROPERTY OF o_sheet 'Columns' = o_column.
PERFORM fill_cell USING 1 2 1 1
'Mechanical spare parts of TFS machines' 16.
* Ende Zellen verbinden
* Zeilen 3 und 4
* Range definieren: Start
CALL METHOD OF excel 'Cells' = o_start
EXPORTING
#1 = 3
#1 = 2.
* Range definieren: Ende
CALL METHOD OF excel 'Cells' = o_end
EXPORTING
#1 = 3
#1 = 3.
* Range aktivieren
CALL METHOD OF excel 'range' = o_sheet
EXPORTING
#1 = o_start
#1 = o_end.
* Range selektieren
CALL METHOD OF o_sheet 'Select'.
* Aktuelle Selektion zuweisen
CALL METHOD OF excel 'Selektion' = o_selection.
GET PROPERTY OF o_sheet 'Columns' = o_column.
PERFORM fill_cell USING 3 2 1 1
'Benennung' 14.
* Range definieren: Start
CALL METHOD OF excel 'Cells' = o_start
EXPORTING
#1 = 4
#1 = 2.
* Range definieren: Ende
CALL METHOD OF excel 'Cells' = o_end
EXPORTING
#1 = 4
#1 = 3.
* Range aktivieren
CALL METHOD OF excel 'range' = o_sheet
EXPORTING
#1 = o_start
#1 = o_end.
* Range selektieren
CALL METHOD OF o_sheet 'Select'.
* Aktuelle Selektion zuweisen
CALL METHOD OF excel 'Selektion' = o_selection.
GET PROPERTY OF o_sheet 'Columns' = o_column.
PERFORM fill_cell USING 4 2 1 1 'Description' 14.
PERFORM fill_cell USING 3 9 0 1 'Preis' 12.
* CALL METHOD OF excel 'Cells' = o_cells.
* CALL METHOD OF o_cells 'Select'.
* CALL METHOD OF excel 'ActiveSheet' = o_sheet.
CALL METHOD OF excel 'Cells' = o_cells
EXPORTING
#1 = 3 "Zeile
#2 = 9. "Spalte
* CALL METHOD OF excel 'CellFormat' = format.
GET PROPERTY OF o_cells 'CellFormat' = o_int.
* SET PROPERTY OF xlalign 'xlright' = '-4102'.
SET PROPERTY OF o_int 'HorizontalAlignment' = '-4102'. "xlalign.
*Standardzellen füllen
* PERFORM fill_cell USING 3 9 0 1 'Preis' 12.
PERFORM fill_cell USING 3 5 0 1 'Sachnummer' 12.
PERFORM fill_cell USING 3 7 0 1 'Menge' 12.
PERFORM fill_cell USING 4 5 0 1 'part number' 12.
PERFORM fill_cell USING 4 7 0 1 'Quantity' 12.
PERFORM fill_cell USING 4 9 0 1 'Price' 12.
* Angebot ermitteln
PERFORM angebot_ermitteln.
zeile = 4.
LOOP AT t_item.
* CALL METHOD OF workbook 'CLOSE'.
* CALL METHOD OF excel 'QUIT'.
* set property of o_Cells 'Deselect' = 1.
* set property of o_Cells 'Select' = 0.
zeile = zeile + 2.
SELECT SINGLE maktx FROM makt INTO t_item-mtextd
WHERE matnr EQ t_item-matnr
AND spras EQ 'D'.
PERFORM fill_cell USING zeile 2 0 1 t_item-mtextd 12.
zeile = zeile + 1.
SELECT SINGLE maktx FROM makt INTO t_item-mtextd
WHERE matnr EQ t_item-matnr
AND spras EQ 'E'.
PERFORM fill_cell USING zeile 2 1 1 t_item-mtexte 12.
PERFORM get_picture.
zeile = zeile + 2.
CALL METHOD OF excel 'Cells' = o_cells
EXPORTING #1 = zeile
#2 = 2.
SET PROPERTY OF o_cells 'Select' = 1.
PERFORM bild.
SET PROPERTY OF pictures 'Select' = 0.
* PERFORM fill_cell USING zeile 2 0 1 text 12.
PERFORM fill_cell USING zeile 5 0 1 t_item-matnr 12.
zeile = zeile + 2.
PERFORM fill_cell USING zeile 5 1 1 'Empfohlene' 12.
zeile = zeile + 1.
PERFORM fill_cell USING zeile 5 1 1 'Stückzahl' 12.
zeile = zeile + 1.
PERFORM fill_cell USING zeile 5 1 1 'Recommended' 12.
PERFORM fill_cell USING zeile 7 1 1 t_item-menge 12.
PERFORM fill_cell USING zeile 9 1 1 t_item-netpr 12.
zeile = zeile + 1.
PERFORM fill_cell USING zeile 5 1 1 'Quantity' 12.
zeile = zeile + 2.
ENDLOOP.
* PERFORM fill_cell USING 6 1 1 3 'Datum' 12.
* PERFORM fill_cell USING 6 2 0 5 sy-datum 12.
* PERFORM fill_cell USING 7 1 1 3 'Uhrzeit' 14.
* PERFORM fill_cell USING 7 2 0 5 sy-uzeit 14.
CALL METHOD OF map 'SaveAs' EXPORTING #1 = 'c:/temp/test1.xls'.
CALL METHOD OF workbook 'CLOSE'.
CALL METHOD OF excel 'QUIT'.
FREE OBJECT workbook.
FREE OBJECT excel.
ENDIF.
*---------------------------------------------------------------------*
* FORM FILL_CELL *
*---------------------------------------------------------------------*
* --> I Zeile *
* --> J Spalte *
* --> BOLD Fett=1, Normal=0 *
* --> COL Farbe: *
* 1=Schwarz, 2=weiss, 3=rot, 4=grün, 5=blau, 6=gelb *
* --> VAL Wert *
* --> SIZE Größe *
*---------------------------------------------------------------------*
FORM fill_cell USING i j bold col val size.
DATA:
h_zl TYPE ole2_object, " cell
h_f TYPE ole2_object. " font
CALL METHOD OF excel 'Cells' = h_zl
EXPORTING #1 = i #2 = j.
SET PROPERTY OF h_zl 'Value' = val .
GET PROPERTY OF h_zl 'Font' = h_f.
SET PROPERTY OF h_f 'Bold' = bold .
SET PROPERTY OF h_f 'ColorIndex' = col. "Rot
* SET PROPERTY OF h_f 'Size' = 16.
SET PROPERTY OF h_f 'Size' = size.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form angebot_ermitteln
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM angebot_ermitteln.
DATA: count LIKE sy-tabix.
SELECT * FROM vbap INTO TABLE it_vbap
WHERE vbeln EQ wa_vbak-vbeln.
LOOP AT it_vbap INTO wa_vbap.
CLEAR t_item.
count = count + 1.
t_item-posnr = count.
t_item-matnr = wa_vbap-matnr.
t_item-mtextd = wa_vbap-arktx.
t_item-mtexte = wa_vbap-arktx.
t_item-menge = wa_vbap-kwmeng.
t_item-meins = wa_vbap-zieme.
t_item-netpr = wa_vbap-netwr.
t_item-waers = 'EUR'.
APPEND t_item.
ENDLOOP.
ENDFORM. " angebot_ermitteln
*&---------------------------------------------------------------------*
*& Form get_picture
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_picture.
DATA: wa_drad LIKE drad,
files1 LIKE bapi_doc_files2,
application TYPE dappl OCCURS 0 WITH HEADER LINE, "#EC NEEDED
dokuments LIKE bapi_doc_draw2 OCCURS 0 WITH HEADER LINE. "#EC NEEDED
SELECT * FROM drad INTO wa_drad
WHERE dokar EQ 'ZAN'
AND dokob EQ 'MARA'
AND objky EQ t_item-matnr
ORDER BY dokvr DESCENDING.
EXIT.
ENDSELECT.
dokuments-documenttype = wa_drad-dokar.
dokuments-documentnumber = wa_drad-doknr.
dokuments-documentversion = wa_drad-dokvr.
dokuments-documentpart = wa_drad-doktl.
APPEND dokuments.
application = 'ZJP'.
APPEND application.
files1-wsapplication = 'ZJP'.
CALL FUNCTION 'BAPI_DOCUMENT_CHECKOUTVIEW2'
EXPORTING
documenttype = wa_drad-dokar
documentnumber = wa_drad-doknr
documentpart = wa_drad-doktl
documentversion = wa_drad-dokvr
documentfile = files1
getstructure = '1'
getcomponents = 'X'
originalpath = 'C:\TEMP\'
hostname = ' '
getheader = 'X'
TABLES
documentfiles = files2.
READ TABLE files2 INDEX 1.
text = files2-docfile.
ENDFORM. " get_picture
*&---------------------------------------------------------------------*
*& Form bild
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM bild.
* Falls die Methode für o_Cell hier aufgerufen wird, fehlen die Bilder
* call method of excel 'Cells' = o_Cells
* exporting #1 = zeile
* #2 = 2.
* set property of o_cells 'Select' = 1.
CALL METHOD OF excel 'ActiveSheet' = o_sheet.
* CALL METHOD OF excel 'Cells' = o_cells
*
* EXPORTING #1 = zeile
*
* #2 = 2.
* Range definieren: Start
* CALL METHOD OF excel 'Cells' = o_start
* EXPORTING
* #1 = zeile
* #1 = 2.
* zeile = Zeile + 21.
** Range definieren: Ende
* CALL METHOD OF excel 'Cells' = o_end
* EXPORTING
* #1 = zeile
* #1 = 10.
*
** Range aktivieren
* CALL METHOD OF excel 'range' = o_sheet
* EXPORTING
* #1 = o_start
* #1 = o_end.
*
** Range selektieren
* CALL METHOD OF o_sheet 'Select'.
* SET PROPERTY OF o_cells 'Select' = 1.
CALL METHOD OF o_sheet 'Pictures' = pictures.
* EXPORTING #1 = 1.
CALL METHOD OF pictures 'Insert'
EXPORTING #1 = text.
SET PROPERTY OF pictures 'Height' = 70.
SET PROPERTY OF pictures 'Width' = 150.
SET PROPERTY OF pictures 'Select' = 1.
*{ INSERT T05K900343 1
CALL METHOD OF map 'SaveAs' EXPORTING #1 = 'c:/temp/test1.xls'.
free object pictures.
*} INSERT
ENDFORM. " bild