microsoft word

#1
Hi
I have just come back into working with Progress and am having problems with creating a MicroSoft Word document automatically from within Progress.
I have most of the requisite data in a 'working text document' called test.txt but want to add extras to it and then have it saved as a MicroSoft document .DOC without any operator interference.

Any help greatly appreciated

Regards
Mike
 

Rob Fitzpatrick

ProgressTalk.com Sponsor
#2
One approach you can use to create Word documents from ABL is COM Automation. The article below contains a simple code sample.
Progress KB - ACTIVEX - How to insert data into a MS Word document
Progress KB - Tips for using Excel and Word via ActiveX Automation

It can be quite slow compared with other approaches but you can do it with no external dependencies and it is probably the most straightforward way if you're looking for a simple way to get started. Other approaches, at a high level, are creating an Office Open XML file yourself or using a third-party library like DocxFactory. I haven't included a link to that as I'm not sure if it's still an active project.

You mentioned ".DOC" specifically. Did you mean "a Word document" in general, or specifically the binary .doc format (the default in Word 2003 and earlier), as opposed to the zip/xml .docx format (the default in Word 2007+)?
 
#4
One approach you can use to create Word documents from ABL is COM Automation. The article below contains a simple code sample.
Progress KB - ACTIVEX - How to insert data into a MS Word document
Progress KB - Tips for using Excel and Word via ActiveX Automation

It can be quite slow compared with other approaches but you can do it with no external dependencies and it is probably the most straightforward way if you're looking for a simple way to get started. Other approaches, at a high level, are creating an Office Open XML file yourself or using a third-party library like DocxFactory. I haven't included a link to that as I'm not sure if it's still an active project.

You mentioned ".DOC" specifically. Did you mean "a Word document" in general, or specifically the binary .doc format (the default in Word 2003 and earlier), as opposed to the zip/xml .docx format (the default in Word 2007+)?
Hi Rob,

Thanks for your reply.

I am looking for a Word Document in general - either a .DOC or .DOCX

I found an old program - see below - that Creates a Word document and puts in the contents of the incoming file into that word document - but leaves the Word Document open on the screen. If possible I would like this to close the document without seeing the word document at all.

I don't know if this is feasible .

Regards
Mike
Code:
DEF VAR fullname AS CHAR FORMAT "x(100)" NO-UNDO.
DEF VAR outname AS CHAR FORMAT "x(20)" NO-UNDO INITIAL "word\mctest.doc".
DEF VAR coutname AS CHAR FORMAT "x(50)" NO-UNDO.
DEFINE VARIABLE wdFormatText       AS INTEGER  INITIAL 1  NO-UNDO.


ASSIGN fullname = "C:\mike\mctest.lst"
       outname =  "word\mctest.doc"
       coutname = "c:\mike\word\mctest.doc".

/* Open original file in Microsoft Word and save it as a text file */
DEFINE VARIABLE chWord AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chDoc AS COM-HANDLE NO-UNDO.

CREATE "Word.application" chWord.
chDoc = chWord:Documents:OPEN(fullName).
chWord:ActiveDocument:SaveAs(coutName,wdFormatText).
PAUSE 0 NO-MESSAGE.
/* chDoc = chWord:Documents:OPEN(cOriginalFileName).
chWord:ActiveDocument:SaveAs(cConvertedFileName,wdFormatText). */
chWord:QUIT(0).
RELEASE OBJECT chWord.

PAUSE 1 NO-MESSAGE.

/* The following Visual Style parameters define the initial state of the application's main window. */
&GLOBAL-DEFINE SW-SHOWNORMAL 1         /* Start the application in a normal size window. */
&GLOBAL-DEFINE SW-SHOWMINIMIZED 2      /* Start the application minimized. Show an icon at the bottom of the screen. */
&GLOBAL-DEFINE SW-SHOWMAXIMIZED 3      /* Start the application in a maximized window. */
&GLOBAL-DEFINE SW-SHOWNOACTIVATE 4     /* Start the application but set the focus back to the calling program. */
&GLOBAL-DEFINE SW-SHOWMINNOACTIVE 7    /* Start the application minimized and set the focus back to the calling program. */

/* Variable Defininition */
DEFINE VARIABLE cProgramName AS CHARACTER NO-UNDO.   /* The windows program to run.  In this example MS WORD. */
DEFINE VARIABLE cFileName AS CHARACTER NO-UNDO.      /* The file to be opened by this instance of MS WORD.    */
DEFINE VARIABLE iReturnResult AS INTEGER NO-UNDO.    /* The return result value of the WinExe API function.   */

/* Intialize the program name and optionally the file name argument of the command to be run */
ASSIGN
    cProgramName = "C:\Program Files\Microsoft Office\OFFICE\WINWORD.EXE"
    cFileName    = coutname.


ASSIGN
    fullname = SEARCH(cProgramName).


/* Launch MS WORD in a normal window and open the specified document */
RUN WinExec (INPUT cProgramName + CHR(32) + cFileName, INPUT {&SW-SHOWNORMAL}, OUTPUT iReturnResult).

/* Display error message and code ONLY if WinExec failed to launch the program */
IF iReturnResult < 32 THEN
    MESSAGE "Application Failed:" iReturnResult VIEW-AS ALERT-BOX.

/* EXTERNAL PROCEDURE definition of the WinExec API function */
PROCEDURE WinExec EXTERNAL "KERNEL32.DLL":
    DEFINE INPUT PARAMETER ProgramName AS CHARACTER.
    DEFINE INPUT PARAMETER VisualStyle AS LONG.
    DEFINE RETURN PARAMETER StatusCode AS LONG.
END PROCEDURE.
 
Last edited by a moderator:

Rob Fitzpatrick

ProgressTalk.com Sponsor
#5
I found an old program - see below - that Creates a Word document and puts in the contents of the incoming file into that word document - but leaves the Word Document open on the screen.
It appears that after creating the file, the Word instance is closed. Then, for some reason, a second Word instance is created to view the file:
Code:
/* Launch MS WORD in a normal window and open the specified document */
RUN WinExec (INPUT cProgramName + CHR(32) + cFileName, INPUT {&SW-SHOWNORMAL}, OUTPUT iReturnResult).
Try removing the code after RELEASE OBJECT chWord.
 
Top