#DEFINE wdHeaderFooterPrimary 1 #DEFINE wdGray25 16 #DEFINE wdStyleTypeParagraph 1 #DEFINE wdCaptionNumberStyleArabic 0 #DEFINE wdAlignPageNumberCenter 1 #DEFINE wdAlignParagraphCenter 1 #DEFINE wdCollapseEnd 0 #DEFINE wdLineStyleSingle 1 #DEFINE wdLineStyleNone 0 #DEFINE wdLineWidth050Point 4 #DEFINE CR CHR(13) RELEASE ALL LIKE o* PUBLIC oWord LOCAL oDoc, oRange, cText, oHeaderStyle oWord = CreateObject("Word.Application") oWord.Visible = .T. oDoc = oWord.Documents.Add() * Create a style for the header text oHeaderStyle = oDoc.Styles.Add("CenteredHeader", wdStyleTypeParagraph) WITH oHeaderStyle .BaseStyle = oDoc.Styles["Heading 1"] .ParagraphFormat.Alignment = wdAlignParagraphCenter ENDWITH * Add a header WITH oDoc.Sections[1].Headers[ wdHeaderFooterPrimary ] oRange = .Range() WITH oRange .Text = "Tasmanian Traders" .Style = oHeaderStyle .Shading.BackgroundPatternColorIndex = wdGray25 ENDWITH ENDWITH * Add a centered page number in the footer WITH oDoc.Sections[1].Footers[ wdHeaderFooterPrimary ].PageNumbers .Add() .NumberStyle = wdCaptionNumberStyleArabic ENDWITH oDoc.Sections[1].Footers[ wdHeaderFooterPrimary ].PageNumbers[1].Alignment = ; wdAlignPageNumberCenter * Now create some content for the document. * Get a list of customers organized by country. * Sort alphabetically within countries. SELECT Company_Name, Country ; FROM _SAMPLES+"\TasTrade\Data\Customer" ; ORDER BY Country, Company_Name ; INTO CURSOR CustomerByCountry * Title for document oRange = oDoc.Range() oRange.InsertAfter("Customers By Country" + CR) oRange.Style = oDoc.Styles("Heading 1") oRange.Collapse( wdCollapseEnd ) * Loop through cursor. Put each country name bordered in heading 2 style. * Then list each customer in that country. LOCAL cCurrentCountry cCurrentCountry = "" cText = "" SCAN IF NOT (Country==cCurrentCountry) * New country. oRange.InsertAfter( cText + CR ) oRange.Style = oDoc.Styles("Normal") cText = "" oRange.Collapse( wdCollapseEnd ) WITH oRange .InsertAfter( Country + CR ) .Style = oDoc.Styles("Heading 2") .Borders.OutsideLineStyle = wdLineStyleSingle .Borders.OutsideLineWidth = wdLineWidth050Point ENDWITH oRange.Collapse( wdCollapseEnd ) oRange.InsertAfter( CR ) oRange.Borders.OutsideLineStyle = wdLineStyleNone ENDIF cText = cText + Company_Name + CR cCurrentCountry = Country ENDSCAN oRange.InsertAfter( cText ) oRange.Style = oDoc.Styles("Normal") USE IN CustomerByCountry USE IN Customer oDoc.PrintPreview()