siehe auch http://www.tricktresor.de/blog/erzeugun ... dokuments/*&---------------------------------------------------------------------*
*& Report ZWORD_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zword_test.
INCLUDE ole2incl .
*--Global variables
*--Variables to hold OLE object and entity handles
DATA gs_word TYPE ole2_object . "OLE object handle
DEFINE create_new_instance.
create object gs_word 'Word.Basic.8' .
END-OF-DEFINITION.
DEFINE appshow.
call method of gs_word 'AppShow' .
END-OF-DEFINITION.
DEFINE apphide.
call method of gs_word 'AppHide' .
END-OF-DEFINITION.
DEFINE filenew.
call method of gs_word 'FileNew'
exporting
#1 = 'normal.dot'.
END-OF-DEFINITION.
DEFINE fileopen.
call method of gs_word 'FileOpen'
exporting
#1 = &1.
END-OF-DEFINITION.
DEFINE filesaveas.
call method of gs_word 'FileSaveAs'
exporting
#1 = &1.
END-OF-DEFINITION.
DEFINE filecloseall.
call method of gs_word 'FileCloseAll'
exporting
#1 = 2.
END-OF-DEFINITION.
DEFINE editreplace.
*EditReplace [.Find = text] [.Replace = text]
*[.Direction = number] [.MatchCase = number]
*[.WholeWord = number]
*[.PatternMatch = number]
*[.SoundsLike = number] [.FindNext]
*[.ReplaceOne] [.ReplaceAll]
*[.Format = number] [.Wrap = number]
call method of gs_word 'EditReplace'
exporting
#01 = &1
#02 = &2
#03 = 0
#04 = 0
#05 = 0
#06 = 0
#07 = 0
#08 = 0
#09 = 0
#10 = 1
#11 = 0
#12 = 1.
END-OF-DEFINITION.
DEFINE font.
call method of gs_word 'Font' exporting #01 = &1.
call method of gs_word 'FontSize' exporting #1 = &2.
END-OF-DEFINITION.
DEFINE insert1.
call method of gs_word 'Insert' exporting #1 = &1.
END-OF-DEFINITION.
DEFINE viewheader.
call method of gs_word 'ViewHeader' .
END-OF-DEFINITION.
DEFINE closeviewheaderfooter.
*** Kopffenster wieder schließen
call method of gs_word 'CloseViewHeaderFooter' .
END-OF-DEFINITION.
DEFINE CharCol.
*Color Explanation
*0 (zero) Auto
*1 Black
*2 Blue
*3 Cyan
*4 Green
*5 Magenta
*6 Red
*7 Yellow
*8 White
*9 Dark Blue
*10 Dark Cyan
*11 Dark Green
*12 Dark Magenta
*13 Dark Red
*14 Dark Yellow
*15 Dark Gray
*16 Light Gray
* &1 = integer !!!
call method of gs_word 'CharColor'
exporting
#01 = &1.
END-OF-DEFINITION.
PERFORM create_instance.
*FormatPageNumber [.ChapterNumber = number] [, .NumRestart = number] [, .NumFormat = number] [, .StartingNum = number] [, .Level = number] [, .Separator = number]
*CALL METHOD OF gs_word 'FormatPageNumber'
* EXPORTING
* #01 = 0
* #02 = 0
* #03 = 1.
CALL METHOD OF gs_word 'InsertPageNumbers'
EXPORTING
#01 = 0
#02 = 1
#03 = 0.
* 0= header/1=footer
* 0=links/1=Mitte/2=rechts/3 Inside
* (left on odd pages and right on even pages)
* 4 Outside (right on odd pages and left on even pages)
* If 1, the field is included in the header or footer on the first page.
PERFORM close_instance.
EXIT.
*&---------------------------------------------------------------------*
*& Form create_instance
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM create_instance.
DATA lv_file(80).
create_new_instance.
appshow.
fileopen 'c:\temp\777.doc'.
filesaveas 'c:\temp\888.doc'.
ENDFORM. "Create_Instance
*&---------------------------------------------------------------------*
*& Form Close_Instance
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM close_instance.
DATA lv_file(80).
filesaveas 'c:\temp\888.doc'.
filecloseall.
* Word schliessen
CALL METHOD OF gs_word 'AppClose'.
FREE OBJECT gs_word.
ENDFORM. "Close_Instance