Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word Automation
Message
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
00191231
Message ID:
00191310
Views:
62
>I need to do a Word Merge.
>
>I have so far been succesfull at
>getting a single record to print
>from VFP into Word 97 as in a form
>letter using the following syntax:
>
> oWordObj.ww7_EditGoto ("contact")
> oWordObj.Insert (TestData.Contact)
>
>This code works fine with predefined
>bookmarks in Word. Can anyone help me
>with sending multiple rows of data.?
>
>How do I get records from a VFP table
>to merge into Word in a tabular format
>as in:
>
> HEADER1 HEADER2 HEADER 3
>----------------------------------------
> Column1 Data Col2 Data Col3 Data
> Column1 Data Col2 Data Col3 Data
> Column1 Data Col2 Data Col3 Data
>
>
>
>Thanks in advance

Cetin Bazoz has an intersting mail merge class here in the libs (mmerge.zip).
Hereafter you'll find another approach I extracted from an article in Foxpress (www.fpress.com). It will print the table structures of all the tables in a given directory. So it handles very well an unknown number of tables with an unknown number of fields.
PRIVATE lcDir, ;
  lnArchives, ;
  laFiles, ;
  lnCount, ;
  x

IF ! "FOXTOOLS" $ UPPER(SET("LIBRARY"))
  SET LIBRARY TO HOME() + "FOXTOOLS" ADDITIVE
ENDIF

lcDir = GETDIR(CURDIR(), "Où sont les tables?")

IF EMPTY(lcDir)
  = MESSAGEBOX ("Pas de répertoire sélectionné!")
  RETURN
ENDIF

lnArchives = ADIR(laFiles, (lcDir+"*.DBF"))

oWord = CREATEOBJECT("Word.Application")
oWord.Visible = .T.
oWord.Documents.Add

FOR lnCount = 1 TO lnArchives
  x = lnCount
  USE (lcDir + laFiles[lnCount, 1])
  DO WriteTable
ENDFOR

oWord.WindowState = 1

*-- Column 1: name of field
*-- Column 2: type
*-- Column 3: size
*-- Column 4: width
*-- Column 5: description


PROCEDURE WriteTable
  PRIVATE lnFields, ;
    laFields, ;
    lcDBF

  lnFields = AFIELDS[laFields]
  lcDBF = JustFname(DBF())

  oWord.activeDocument.Content.InsertAfter(lcDBF)
  oWord.activeDocument.Content.InsertParagraphAfter
  oWord.selection.moveDown 1

  oWord.activeDocument.range(oWord.activeDocument.Paragraphs(1).Range.start, ;
    oWord.activeDocument.Paragraphs(lnCount + 1).Range.end)
  oWord.selection.moveDown 1
  oWord.activeDocument.Content.tables.add(oWord.selection.range, lnFields+1, 5)

  *-- write the header of each table
  oWord.activeDocument.Tables(x).cell(1,1).Range.InsertAfter("Name")
  oWord.activeDocument.Tables(x).cell(1,2).Range.InsertAfter("Data Type")
  oWord.activeDocument.Tables(x).cell(1,3).Range.InsertAfter("Size")
  oWord.activeDocument.Tables(x).cell(1,4).Range.InsertAfter("Width")
  oWord.activeDocument.Tables(x).cell(1,5).Range.InsertAfter("Description")

  oWord.activeDocument.Tables(x).Rows(1).Select
  oWord.Selection.Font.Size = 14
  oWord.Selection.Font.Bold = .T.

  LOCAL lnCount

  FOR lnCount = 1 TO lnFields
    oWord.activeDocument.Tables(x).cell(lnCount+1, 1).Range.InsertAfter(laFields[lnCount, 1])
    oWord.activeDocument.Tables(x).cell(lnCount+1, 2).Range.InsertAfter(laFields[lnCount, 2])
    oWord.activeDocument.Tables(x).cell(lnCount+1, 3).Range.InsertAfter(laFields[lnCount, 3])
    oWord.activeDocument.Tables(x).cell(lnCount+1, 4).Range.InsertAfter(laFields[lnCount, 4])
  ENDFOR

  FOR lnCount = 1 TO lnFields+3
    oWord.Selection.moveDown
  ENDFOR

  oWord.activeDocument.Content.InsertParagraphAfter

ENDPROC
José
Previous
Reply
Map
View

Click here to load this message in the networking platform