SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Create file in MS Word



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> OLE2, Excel, WinWord
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sat Oct 06, 2007 1:20 am    Post subject: Create file in MS Word Reply with quote

Create
Code:
create object msword 'Word.Basic'.
call method of msword 'FileNew'
exporting #1 = 'normal.dot'.
call method of msword 'AppShow'.
...
...
call method of msword 'Drawtextbox'.
call method of msword 'DrawSetInsertToTextbox'.


Open
Code:

CALL METHOD OF gs_documents 'Open' = gs_newdoc
EXPORTING #1 = '<filepath\filename>'
#2 = 1
#3 = 1 .

It is the third parameter (#3) which passes read-only option. It must be set to '1' if you want to open the document in 'Read-only' mode.

Check these following SAP programs
"SAPRDEMOWORD97INTEGRATION""RSDEMO01"


Example 2
This ABAP code needs a Word file in somewhere in local PC directory tree. The word file must be already configured as a mail merge template. The data source is not controlled by this ABAP code, so the Word file must have it.

T.Yamagiwa

Code:

REPORT zyamagi_wordprint  MESSAGE-ID sy.

*Working directory such as SapWorkDir
PARAMETERS : p_file LIKE rlgrap-filename.

INCLUDE ole2incl.
INCLUDE docsincl.

DATA: h_word  TYPE ole2_object,
      h_docs  TYPE ole2_object,
      h_doc   TYPE ole2_object,
      h_merge TYPE ole2_object.

INITIALIZATION.
  CALL FUNCTION 'WS_QUERY'
       EXPORTING
            query  = 'CD'
       IMPORTING
            return = p_file.
  CONCATENATE p_file 'Merge.DOC' INTO p_file.

START-OF-SELECTION.

* Create Word Application object
  IF h_word-header = space OR h_word-handle EQ -1.
    CREATE OBJECT h_word  'WORD.APPLICATION'.
    IF sy-subrc NE 0.
      MESSAGE i002 WITH sy-msgli.
    ELSE.
      SET PROPERTY OF  h_word  'VISIBLE' = 1.
    ENDIF.
  ENDIF.
* Get Documsnts collection as property of Application object
  GET PROPERTY OF h_word 'DOCUMENTS'  = h_docs.
* Open a word file
  CALL METHOD OF h_docs 'OPEN' = h_doc
                        EXPORTING  #1 = p_file.
* Invoke mail merge
* The Word windows will be visible
  GET PROPERTY OF h_doc 'MAILMERGE' = h_merge.
  SET PROPERTY OF h_merge 'DESTINATION' = 1.
  CALL METHOD OF h_merge 'EXECUTE'.
* Terminate Word
  CALL METHOD OF h_word 'QUIT' EXPORTING #1 = 0.
* Free objects
  FREE OBJECT : h_merge,
                h_doc,
                h_docs,
                h_word.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> OLE2, Excel, WinWord All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.