>* 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 >