Skip to Content
author's profile photo Former Member
Former Member

OLE-Word with table

Hi,

i use OLE-Word to create a table in a word document and fill them.

That's work OK, but i will position the table on a specific Positon on the page.

Position shell be horizontal 7 and vertical 8.

I have tried it with recording in word, bot i don't know the statements in ABAP.

Has anyone an idea to solve it or an example?

thanks.

Regards, Dieter.

Edited by: Dieter Gröhn on Jun 16, 2008 10:34 AM

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 16, 2008 at 09:51 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 16, 2008 at 09:49 AM

    Here my code:

    REPORT ZGRO_MS_WORD_OLE_FORMLETTER_T0.

    *--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_DOCUMENT TYPE OLE2_OBJECT . "Documents

    DATA GS_ACTIV_DOC 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_BORDER TYPE OLE2_OBJECT . "Table border

    DATA GS_CELL TYPE OLE2_OBJECT . "One cell of a table

    DATA GS_PARAGRAPH TYPE OLE2_OBJECT . "Paragraph

    START-OF-SELECTION .

    *

    PERFORM WORD_APPLIKATION.

    *

    PERFORM TABELLE_ERSTELLEN.

    *

    PERFORM TABELLE_ZELLE.

    *

    FREE OBJECT GS_WORD .

    *

    ***********************************************************************

    FORM WORD_APPLIKATION.

    *

    *--Creating OLE object handle variable

    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_DOCUMENT.

    CALL METHOD OF GS_DOCUMENT 'Add' .

    *--Getting active document handle

    GET PROPERTY OF GS_WORD 'ActiveDocument' = GS_ACTIV_DOC .

    *--Getting applications handle

    GET PROPERTY OF GS_ACTIV_DOC '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 .

    *

    ENDFORM. "word_applikation

    ***********************************************************************

    FORM TABELLE_ERSTELLEN.

    ***

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

    GET PROPERTY OF GS_ACTIV_DOC 'Tables' = GS_TABLES .

    GET PROPERTY OF GS_SELECTION 'Range' = GS_RANGE .

    *--Adding a table

    CALL METHOD OF GS_TABLES 'Add' = GS_TABLE

    EXPORTING #1 = GS_RANGE

    #2 = '1' "Number of rows

    #3 = '1'. "Number of columns

    *--Setting border attribute

    GET PROPERTY OF GS_TABLE 'Borders' = GS_BORDER .

    SET PROPERTY OF GS_BORDER 'Enable' = '0' . "0 o. 1

    ***

    DATA GS_ROWS TYPE OLE2_OBJECT.

    GET PROPERTY OF GS_TABLE 'Rows' = GS_ROWS.

    SET PROPERTY OF GS_ROWS 'WrapAroundText' = '1'.

    SET PROPERTY OF GS_ROWS 'HorizontalPosition' = '3'.

    SET PROPERTY OF GS_ROWS 'RelativeHorizontalPosition' = '1'.

    SET PROPERTY OF GS_ROWS 'VerticalPosition' = '8'.

    SET PROPERTY OF GS_ROWS 'RelativeVerticalPosition' = '1'.

    set property of GS_ROWS 'AllowOverlap' = '0'.

    ***

    ENDFORM. "Tabelle_erstellen

    ***********************************************************************

    FORM TABELLE_ZELLE.

    *

    *--Getting cell coordinates

    CALL METHOD OF GS_TABLE 'Cell' = GS_CELL

    EXPORTING #1 = '1'

    #2 = '1'.

    *--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' = 'Test' .

    *

    ENDFORM. "TABELLE_Zelle

    ***********************************************************************

    in Word i record and get this:

    Sub Makro1()

    '

    ' Makro1 Makro

    ' Makro aufgezeichnet am 16.06.2008

    '

    ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _

    1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _

    wdAutoFitFixed

    With Selection.Tables(1)

    If .Style <> "Tabellengitternetz" Then

    .Style = "Tabellengitternetz"

    End If

    .ApplyStyleHeadingRows = True

    .ApplyStyleLastRow = True

    .ApplyStyleFirstColumn = True

    .ApplyStyleLastColumn = True

    End With

    With Selection.Tables(1).Rows

    .WrapAroundText = True

    .HorizontalPosition = CentimetersToPoints(2)

    .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage

    .DistanceLeft = CentimetersToPoints(0.25)

    .DistanceRight = CentimetersToPoints(0.25)

    .VerticalPosition = CentimetersToPoints(8)

    .RelativeVerticalPosition = wdRelativeVerticalPositionPage

    .DistanceTop = CentimetersToPoints(0)

    .DistanceBottom = CentimetersToPoints(0)

    .AllowOverlap = False

    End With

    End Sub

    i will translate it in abap. how can i do it.

    i tried something in FORM TABELLE_ERSTELLEN but i can see the table, but i don't get the right position.

    Any idea?

    thanks.

    Regards, Dieter

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.