Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP6SP5 and Word Automation using Word Templates
Message
 
À
03/03/2003 09:14:41
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00758576
Message ID:
00760366
Vues:
16
Thank you very much Tamar, appreciate your kindness in sharing your code with me.

>>Thanks again Tamar. Could you post a simple VFP code eg. if it is not asking too much, this will avoid a lot of reinventing the wheel work on my side.
>>
>>
>
>
>This example comes from the book Della Martin and I wrote, "Microsoft Office Automation with Visual FoxPro". Sorry about the lack of indentation; I'm on the road right now, so I lifted this from the CHM, where there's a problem with indentation.
>
>
>* 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()
>
>OPEN DATABASE (_SAMPLES + "Tastrade\Data\Tastrade")
>
>USE CUSTOMER
>
>GO RAND()*RECCOUNT() && pick a customer at random
>
>* Open the Order History view, which contains
>
>* a summary of orders for one customer.
>
>SELECT 0
>
>USE "Order History" ALIAS OrderHistory
>
>* Find out how many records.
>
>nRecCount = _TALLY
>
>oRange = oWord.ActiveDocument.Range()
>
>* 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, 4)
>
>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
>
>.Cell[1,1].Range.ParagraphFormat.Alignment = wdAlignParagraphRight
>
>.Cell[1,1].Range.InsertAfter("Order Number")
>
>
>.Cell[1,2].Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
>
>.Cell[1,2].Range.InsertAfter("Date")
>
>.Cell[1,3].Range.ParagraphFormat.Alignment = wdAlignParagraphRight
>
>.Cell[1,3].Range.InsertAfter("Total")
>
>.Cell[1,4].Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
>
>.Cell[1,4].Range.InsertAfter("Paid?")
>
>
>* 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
>
>* Compute total along the way
>
>nTotalOrders = 0
>
>FOR nRow = 1 TO nRecCount
>
>WITH .Rows[nRow + 1]
>
>.Cells[1].Range.InsertAfter( Order_Id )
>
>.Cells[2].Range.InsertAfter( TRANSFORM(Order_Date, "@D") )
>
>.Cells[3].Range.InsertAfter( TRANSFORM(Ord_Total, "$$$$$$$$$9.99") )
>
>* Put an X in fourth column, if paid; blank otherwise
>
>IF Paid
>
>.Cells[4].Range.InsertAfter("X")
>
>ENDIF
>
>ENDWITH
>
>
>* Add a new row
>
>.Rows.Add()
>
>
>* Running Total
>
>nTotalOrders = nTotalOrders + Ord_Total
>
>SKIP
>
>ENDFOR
>
>* Add a double line before the totals
>
>.Rows[nRecCount + 2].Borders[ wdBorderTop ].LineStyle = wdLineStyleDouble
>
>
>* Put total row in
>
>WITH .Rows[ nRecCount + 2]
>
>.Cells[1].Range.InsertAfter("Total")
>
>.Cells[3].Range.InsertAfter(TRANSFORM(nTotalOrders, "$$$$$$$$$9.99"))
>
>ENDWITH
>
>
>* Size columns. For simplicity, let Word
>
>* do the work.
>
>.Columns.Autofit
>
>ENDWITH
>
>RETURN
>
Regards
Bhavbhuti
___________________________________________
Softwares for Indian Businesses at:
http://venussoftop.tripod.com
___________________________________________
venussoftop@gmail.com
___________________________________________
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform