Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word report
Message
 
À
10/10/2000 03:55:25
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire de rapports & Rapports
Titre:
Divers
Thread ID:
00427180
Message ID:
00427205
Vues:
15
>Can anyone advise me on the following.
>
>I am creating a statistical report in word 97 to be run from vfp - what would be the best way to incorporate the figures into word if I had the figures in arrays in VFP.
>
>The report is 9 rows by 9 columns.
>

Here's a start on the Automation code. This code is modified from an example in the book, Microsoft Office Automation with Visual Foxpro (Tamar Granor/Della Martin), to fit your 9 column array, and has code to put in a header row(amended from the original of using data from a sample database. Totalling the columns was also removed).

Hope this helps!

- della Martin



* Amended version of OrderTblFormat.PRG, amended by Della Martin
* Copyright (c)2000, Tamar Granor and Della Martin
* From _Automating Microsoft Office with Visual FoxPro_,
* Hentzenwerke Press. www.hentzenwerke.com

* Create a Word table with order information for one customer
* Set up the table with two rows, formatting the second row for
* the data. Then add rows as needed for each record.
#DEFINE wdStory 6
#DEFINE wdCollapseEnd 0
#DEFINE CR CHR(13)
#DEFINE wdBorderTop -1
#DEFINE wdLineStyleDouble 7
#DEFINE wdAlignParagraphLeft 0
#DEFINE wdAlignParagraphCenter 1
#DEFINE wdAlignParagraphRight 2

RELEASE ALL LIKE o*
PUBLIC oWord
LOCAL oRange, oTable, nRecCount, nTotalOrders
LOCAL nRow

oWord = CreateObject("Word.Application")
oWord.Documents.Add()

* Set up a font for the table
oRange.Font.Name = "Arial"
oRange.Font.Size = 12

* Move to the end of the document
* Leave two empty lines
oRange.MoveEnd( wdStory )
oRange.Collapse( wdCollapseEnd )
oRange.InsertAfter( CR + CR )
oRange.Collapse( wdCollapseEnd )

* Add a table with two rows
oTable = oWord.ActiveDocument.Tables.Add( oRange, 2, 9)
WITH oTable
* Set up borders and shading.
* First, remove all borders
.Borders.InsideLineStyle = .F.
.Borders.OutsideLineStyle = .F.

* Shade first row for headings
.Rows[1].Shading.Texture = 100

* Put heading text in and set alignment
* These alignments are from the example in the book...amend as needed
.Cell[1,1].Range.ParagraphFormat.Alignment = wdAlignParagraphRight
.Cell[1,1].Range.InsertAfter("Column 1")

.Cell[1,2].Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Cell[1,2].Range.InsertAfter("Column 2")

.Cell[1,3].Range.ParagraphFormat.Alignment = wdAlignParagraphRight
.Cell[1,3].Range.InsertAfter("Column 3")

.Cell[1,4].Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Cell[1,4].Range.InsertAfter("Column 4")

**** Continue adding headers for each of the 9 columns, above

* Format data cells
.Cell[2,1].Range.ParagraphFormat.Alignment = wdAlignParagraphRight
.Cell[2,3].Range.ParagraphFormat.Alignment = wdAlignParagraphRight
.Cell[2,4].Range.ParagraphFormat.Alignment = wdAlignParagraphCenter

* Add data and format

FOR nRow = 1 TO nRecCount

WITH .Rows[nRow + 1]
.Cells[1].Range.InsertAfter( aMyArray[nRow, 1])
.Cells[2].Range.InsertAfter( aMyArray[nRow, 2])
.Cells[3].Range.InsertAfter( aMyArray[nRow, 3])
.Cells[4].Range.InsertAfter( aMyArray[nRow, 4])
.Cells[5].Range.InsertAfter( aMyArray[nRow, 5])
.Cells[6].Range.InsertAfter( aMyArray[nRow, 6])
.Cells[7].Range.InsertAfter( aMyArray[nRow, 7])
.Cells[8].Range.InsertAfter( aMyArray[nRow, 8])
.Cells[9].Range.InsertAfter( aMyArray[nRow, 9])
ENDWITH

* Add a new row
.Rows.Add()
ENDFOR

* Size columns. For simplicity, let Word
* do the work.
.Columns.Autofit

ENDWITH

RETURN
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform