Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

OLE Word Documentation

Former Member
0 Likes
1,930

Dear all,

Where can i found a documentation about OLE using microsoft word ???

Thanks.

Dear all,

Where can i found a documentation about OLE using microsoft word ???

Thanks.

2 REPLIES 2
Read only

Former Member
0 Likes
718

hi check this ..

OLE

http://www.sapgenie.com/abap/ole.htm

http://help.sap.com/saphelp_46c/helpdata/en/59/ae3f2e488f11d189490000e829fbbd/frameset.htm

this is for word

REPORT YTEST .

*--Include for OLE-enabling definitions

INCLUDE OLE2INCL .

*--Global variables

*--Variables to hold OLE object and entity handles

DATA GS_WORD TYPE OLE2_OBJECT . "OLE object handle

DATA GS_DOCUMENTS TYPE OLE2_OBJECT . "Documents

DATA GS_ACTDOC TYPE OLE2_OBJECT . "Active document

DATA GS_APPLICATION TYPE OLE2_OBJECT . "Application

DATA GS_OPTIONS TYPE OLE2_OBJECT . "Application options

DATA GS_ACTWIN TYPE OLE2_OBJECT . "Active window

DATA GS_ACTPAN TYPE OLE2_OBJECT . "Active pane

DATA GS_VIEW TYPE OLE2_OBJECT . "View

DATA GS_SELECTION TYPE OLE2_OBJECT . "Selection

DATA GS_FONT TYPE OLE2_OBJECT . "Font

DATA GS_PARFORMAT TYPE OLE2_OBJECT . "Paragraph format

DATA GS_TABLES TYPE OLE2_OBJECT . "Tables

DATA GS_RANGE TYPE OLE2_OBJECT . "Range handle for various ranges

DATA GS_TABLE TYPE OLE2_OBJECT . "One table

DATA GS_TABLE_BORDER TYPE OLE2_OBJECT . "Table border

DATA GS_CELL TYPE OLE2_OBJECT . "One cell of a table

DATA GS_PARAGRAPH TYPE OLE2_OBJECT . "Paragraph

DATA GV_POS(5) TYPE N . "Position information for table

CREATE OBJECT GS_WORD 'WORD.APPLICATION' .

IF SY-SUBRC NE 0.

MESSAGE S000(SU) WITH 'Error while creating OLE object!'.

LEAVE PROGRAM .

ENDIF .

*--Setting object's visibility property

SET PROPERTY OF GS_WORD 'Visible' = '1' .

*--Opening a new document

GET PROPERTY OF GS_WORD 'Documents' = GS_DOCUMENTS .

CALL METHOD OF GS_DOCUMENTS 'Add' .

*--Getting active document handle

GET PROPERTY OF GS_WORD 'ActiveDocument' = GS_ACTDOC .

*--Getting applications handle

GET PROPERTY OF GS_ACTDOC 'Application' = GS_APPLICATION .

*--Setting the measurement unit

GET PROPERTY OF GS_APPLICATION 'Options' = GS_OPTIONS .

SET PROPERTY OF GS_OPTIONS 'MeasurementUnit' = '1' . "CM

*--Getting handle for the selection which is here the character at the

*--cursor position

GET PROPERTY OF GS_APPLICATION 'Selection' = GS_SELECTION .

GET PROPERTY OF GS_SELECTION 'Font' = GS_FONT .

GET PROPERTY OF GS_SELECTION 'ParagraphFormat' = GS_PARFORMAT .

*--Setting font attributes

SET PROPERTY OF GS_FONT 'Name' = 'Arial' .

SET PROPERTY OF GS_FONT 'Size' = '10' .

SET PROPERTY OF GS_FONT 'Bold' = '1' . "Not bold

SET PROPERTY OF GS_FONT 'Italic' = '1' . "Italic

SET PROPERTY OF GS_FONT 'Underline' = '0' . "Not underlined

*--Setting paragraph format attribute

SET PROPERTY OF GS_PARFORMAT 'Alignment' = '2' . "Right-justified

CALL METHOD OF GS_SELECTION 'TypeText'

EXPORTING

#1 = 'This is an OLE example!'.

*--Setting the view to the main document again

SET PROPERTY OF GS_VIEW 'SeekView' = '0' . "Main document view

*--Reseting font attributes for the title

SET PROPERTY OF GS_FONT 'Name' = 'Times New Roman' .

SET PROPERTY OF GS_FONT 'Size' = '16' .

SET PROPERTY OF GS_FONT 'Bold' = '1' . "Bold

SET PROPERTY OF GS_FONT 'Italic' = '0' . "Not Italic

SET PROPERTY OF GS_FONT 'Underline' = '0' . "Not underlined

*--Setting paragraph format attribute

SET PROPERTY OF GS_PARFORMAT 'Alignment' = '1' . "Centered

CALL METHOD OF GS_SELECTION 'TypeText'

EXPORTING

#1 = TEXT-000.

*--Advancing cursor to the new line

CALL METHOD OF GS_SELECTION 'TypeParagraph' .

*--Getting entity handles for the entities on the way

GET PROPERTY OF GS_ACTDOC 'Tables' = GS_TABLES .

GET PROPERTY OF GS_SELECTION 'Range' = GS_RANGE .

*--Adding a table with 3 rows and 2 columns

CALL METHOD OF GS_TABLES 'Add' = GS_TABLE

EXPORTING

#1 = GS_RANGE " Handle for range entity

#2 = '3' "Number of rows

#3 = '2'. "Number of columns

*--Setting border attribute for the table

GET PROPERTY OF GS_TABLE 'Borders' = GS_TABLE_BORDER .

SET PROPERTY OF GS_TABLE_BORDER 'Enable' = '1' . "With border

*--Filling the table with dummy data

*--Reseting font attributes for table content

SET PROPERTY OF GS_FONT 'Name' = 'Garamond' .

SET PROPERTY OF GS_FONT 'Size' = '11' .

SET PROPERTY OF GS_FONT 'Bold' = '0' . "Not bold

SET PROPERTY OF GS_FONT 'Italic' = '0' . "Not Italic

SET PROPERTY OF GS_FONT 'Underline' = '0' . "Not underlined

*--Getting cell coordinates

CALL METHOD OF GS_TABLE 'Cell'

EXPORTING

#1 = '1' "first row

#2 = '1'. "first column

*--Getting the range handle to write the text

GET PROPERTY OF GS_CELL 'Range' = GS_RANGE .

*--Filling the cell

SET PROPERTY OF GS_RANGE 'Text' = 'Venkatesh Appikonda' .

*--Getting cell coordinates

CALL METHOD OF GS_TABLE 'Cell' = GS_CELL

EXPORTING

#1 = '3' "third row

#2 = '2'. "second column

*--Getting the range handle to write the text

GET PROPERTY OF GS_CELL 'Range' = GS_RANGE .

*--Filling the cell

SET PROPERTY OF GS_RANGE 'Text' = 'this is ole example' .

*--Advancing the cursor to the end of the table

GET PROPERTY OF GS_TABLE 'Range' = GS_RANGE .

GET PROPERTY OF GS_RANGE 'End' = GV_POS .

SET PROPERTY OF GS_RANGE 'Start' = GV_POS .

CALL METHOD OF GS_RANGE 'Select' .

*--Skip some lines

DO 10 TIMES .

CALL METHOD OF GS_SELECTION 'TypeParagraph' .

ENDDO.

*--Reseting font attributes for ordinary text

SET PROPERTY OF GS_FONT 'Name' = 'Times New Roman' .

SET PROPERTY OF GS_FONT 'Size' = '12' .

SET PROPERTY OF GS_FONT 'Bold' = '0' . "Not bold

SET PROPERTY OF GS_FONT 'Italic' = '0' . "Not Italic

SET PROPERTY OF GS_FONT 'Underline' = '0' . "Not underlined

*--Setting paragraph format attribute

SET PROPERTY OF GS_PARFORMAT 'Alignment' = '3' . "Justified

*--Indent the paragraph once

GET PROPERTY OF GS_SELECTION 'Paragraphs' = GS_PARAGRAPH .

CALL METHOD OF GS_PARAGRAPH 'Indent' .

CALL METHOD OF GS_SELECTION 'TypeText'

EXPORTING

#1 = TEXT-002.

FREE OBJECT GS_WORD .

this is for excel..

Report ZMULTICOLOR_TEST no standard page heading.

  • this report demonstrates how to send some ABAP data to an

  • EXCEL sheet using OLE automation.

include ole2incl.

  • handles for OLE objects

data: h_excel type ole2_object, " Excel object

h_mapl type ole2_object, " list of workbooks

h_map type ole2_object, " workbook

h_zl type ole2_object, " cell

h_f type ole2_object, " font

h_c type ole2_object. " color

DATA: FILENAME LIKE RLGRAP-FILENAME.

tables: spfli.

data h type i.

  • table of flights

data: it_spfli like spfli occurs 10 with header line.

&----


*& Event START-OF-SELECTION

&----


start-of-selection.

  • read flights

select * from spfli into table it_spfli.

  • display header

uline (61).

write: / sy-vline no-gap,

(3) 'Flg'(001) color col_heading no-gap, sy-vline no-gap,

(4) 'Nr'(002) color col_heading no-gap, sy-vline no-gap,

(20) 'Von'(003) color col_heading no-gap, sy-vline no-gap,

(20) 'Nach'(004) color col_heading no-gap, sy-vline no-gap,

(8) 'Zeit'(005) color col_heading no-gap, sy-vline no-gap.

uline /(61).

  • display flights

loop at it_spfli.

write: / sy-vline no-gap,

it_spfli-carrid color col_key no-gap, sy-vline no-gap,

it_spfli-connid color col_normal no-gap, sy-vline no-gap,

it_spfli-cityfrom color col_normal no-gap, sy-vline no-gap,

it_spfli-cityto color col_normal no-gap, sy-vline no-gap,

it_spfli-deptime color col_normal no-gap, sy-vline no-gap.

endloop.

uline /(61).

  • tell user what is going on

call function 'SAPGUI_PROGRESS_INDICATOR'

exporting

  • PERCENTAGE = 0

text = text-007

exceptions

others = 1.

  • start Excel

create object h_excel 'EXCEL.APPLICATION'.

  • PERFORM ERR_HDL.

set property of h_excel 'Visible' = 1.

  • CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'c:\kis_excel.xls' .

  • PERFORM ERR_HDL.

  • tell user what is going on

call function 'SAPGUI_PROGRESS_INDICATOR'

exporting

  • PERCENTAGE = 0

text = text-008

exceptions

others = 1.

  • get list of workbooks, initially empty

call method of h_excel 'Workbooks' = h_mapl.

perform err_hdl.

  • add a new workbook

call method of h_mapl 'Add' = h_map.

perform err_hdl.

  • tell user what is going on

call function 'SAPGUI_PROGRESS_INDICATOR'

exporting

  • PERCENTAGE = 0

text = text-009

exceptions

others = 1.

  • output column headings to active Excel sheet

perform fill_cell using 1 1 1 200 'Carrier id'(001).

perform fill_cell using 1 2 1 200 'Connection id'(002).

perform fill_cell using 1 3 1 200 'City from'(003).

perform fill_cell using 1 4 1 200 'City to'(004).

perform fill_cell using 1 5 1 200 'Dep. Time'(005).

loop at it_spfli.

  • copy flights to active EXCEL sheet

h = sy-tabix + 1.

if it_spfli-carrid cs 'AA'.

perform fill_cell using h 1 0 000255000 it_spfli-carrid.

elseif it_spfli-carrid cs 'AZ'.

perform fill_cell using h 1 0 168000000 it_spfli-carrid.

elseif it_spfli-carrid cs 'JL'.

perform fill_cell using h 1 0 168168000 it_spfli-carrid.

elseif it_spfli-carrid cs 'LH'.

perform fill_cell using h 1 0 111111111 it_spfli-carrid.

elseif it_spfli-carrid cs 'SQ'.

perform fill_cell using h 1 0 100100100 it_spfli-carrid.

else.

perform fill_cell using h 1 0 000145000 it_spfli-carrid.

endif.

if it_spfli-connid lt 400.

perform fill_cell using h 2 0 255000255 it_spfli-connid.

elseif it_spfli-connid lt 800.

perform fill_cell using h 2 0 077099088 it_spfli-connid.

else.

perform fill_cell using h 2 0 246156138 it_spfli-connid.

endif.

if it_spfli-cityfrom cp 'S*'.

perform fill_cell using h 3 0 155155155 it_spfli-cityfrom.

elseif it_spfli-cityfrom cp 'N*'.

perform fill_cell using h 3 0 189111222 it_spfli-cityfrom.

else.

perform fill_cell using h 3 0 111230222 it_spfli-cityfrom.

endif.

if it_spfli-cityto cp 'S*'.

perform fill_cell using h 4 0 200200200 it_spfli-cityto.

elseif it_spfli-cityto cp 'N*'.

perform fill_cell using h 4 0 000111222 it_spfli-cityto.

else.

perform fill_cell using h 4 0 130230230 it_spfli-cityto.

endif.

if it_spfli-deptime lt '020000'.

perform fill_cell using h 5 0 145145145 it_spfli-deptime.

elseif it_spfli-deptime lt '120000' .

perform fill_cell using h 5 0 015215205 it_spfli-deptime.

elseif it_spfli-deptime lt '180000' .

perform fill_cell using h 5 0 000215205 it_spfli-deptime.

else.

perform fill_cell using h 5 0 115115105 it_spfli-deptime.

endif.

endloop.

  • EXCEL FILENAME

CONCATENATE SY-REPID '_' SY-DATUM6(2) '_' SY-DATUM4(2) '_'

SY-DATUM(4) '_' SY-UZEIT '.XLS' INTO FILENAME.

CALL METHOD OF H_MAP 'SAVEAS' EXPORTING #1 = FILENAME.

free object h_excel.

perform err_hdl.

----


  • FORM FILL_CELL *

----


  • sets cell at coordinates i,j to value val boldtype bold *

----


form fill_cell using i j bold col val.

call method of h_excel 'Cells' = h_zl

exporting

#1 = i

#2 = j.

perform err_hdl.

set property of h_zl 'Value' = val .

perform err_hdl.

get property of h_zl 'Font' = h_f.

perform err_hdl.

set property of h_f 'Bold' = bold .

perform err_hdl.

set property of h_f 'Color' = col.

perform err_hdl.

endform. "FILL_CELL

&----


*& Form ERR_HDL

&----


  • outputs OLE error if any *

----


  • --> p1 text

  • <-- p2 text

----


form err_hdl.

if sy-subrc <> 0.

write: / 'OLE-Automation Error:'(010), sy-subrc.

stop.

endif.

endform. " ERR_HDL

regards,

venkat