This program reads the Customer.DBF available in \FWH\Samples folder and dumps the data onto a table on a word document
Include "FiveWin.ch"
#DEFINE wdAlignParagraphLeft 聽 聽0
#DEFINE wdAlignParagraphCentre 聽1
#DEFINE wdAlignParagraphRight 聽 2
#DEFINE wdStory 聽 聽 聽 聽 聽 聽 聽 聽 6
#DEFINE wdCollapseEnd 聽 聽 聽 聽 聽 0
#DEFINE wdBorderTop 聽 聽 聽 聽 聽 聽-1
#DEFINE wdLineStyleDouble 聽 聽 聽 7
#DEFINE CR 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 CHR(13)
//--------------------------//
Function Main()
Local oWord,oRange,oTable,nRecCount,nRow,nTotSalary:=0
USE \FWH\Samples\CUSTOMER
nRecCount:=RecCount()
oWord:=CREATEOBJECT("Word.Application")
oWord:Documents:Add()
oRange:=oWord:ActiveDocument:Range()
// Move to the end of the document, leave 2 empty lines
oRange:MoveEnd( wdStory )
oRange:Collapse( wdCollapseEnd )
oRange:InsertAfter( CR + CR )
oRange:Collapse( wdCollapseEnd )
// Add a table with 2 rows and 3 columns
oTable:=oWord:ActiveDocument:Tables:Add(oRange,2,3)
WITH OBJECT oTable
聽 聽// Set up borders and shading
聽 聽// If u dont want borders then set the below lines 2 lines to .F.
聽 聽:Borders:InsideLineStyle:=.T.
聽 聽:Borders:OutsideLineStyle:=.T.
聽 聽// Shade first row for headings
聽 聽:Rows[1]:Shading:Texture = 100
聽 聽// Put heading text in and set alignment
聽 聽:Cell(1,1):Range:ParagraphFormat:Alignment:=wdAlignParagraphLeft
聽 聽:Cell(1,1):Range:InsertAfter("Last Name") 聽
聽 聽
聽 聽
聽 聽:Cell(1,2):Range:ParagraphFormat:Alignment:=wdAlignParagraphRight
聽 聽:Cell(1,2):Range:InsertAfter("Salary")
聽 聽:Cell(1,3):Range:ParagraphFormat:Alignment:=wdAlignParagraphLeft
聽 聽:Cell(1,3):Range:InsertAfter("Hire Date")
聽 聽// Format data cells
聽 聽:Cell(2,1):Range:ParagraphFormat:Alignment:=wdAlignParagraphLeft
聽 聽:Cell(2,2):Range:ParagraphFormat:Alignment:=wdAlignParagraphRight
聽 聽:Cell(2,3):Range:ParagraphFormat:Alignment:=wdAlignParagraphLeft
聽 聽// Add data and format
聽 聽nTotSalary:=0 聽
聽 聽For nRow:=1 to 20 // nRecCount
聽 聽 聽 聽WITH OBJECT :Rows[nRow + 1] 聽 聽
聽 聽 聽 聽 聽 聽:Cells[1]:Range:InsertAfter( Customer->LAST 聽)
聽 聽 聽 聽 聽 聽:Cells[2]:Range:InsertAfter( Customer->SALARY 聽) 聽 聽 聽
聽 聽 聽 聽 聽 聽:Cells[3]:Range:InsertAfter( Customer->HIREDATE 聽)
聽 聽 聽 聽END
聽 聽 聽 聽
聽 聽 聽 聽// Add a new Row
聽 聽 聽 聽:Rows:Add()
聽 聽 聽 聽
聽 聽 聽 聽// Calculating total
聽 聽 聽 聽nTotSalary+=Customer->SALARY
聽 聽 聽 聽Skip
聽 聽Next
聽 聽
聽 聽// Total row shade and place total
聽 聽:Rows[ nRow + 1 ]:Shading:Texture = 100
聽 聽WITH OBJECT :Rows[ nRow + 1 ]
聽 聽 聽 聽:Cells[1]:Range:InsertAfter("Total Salary")
聽 聽 聽 聽:Cells[2]:Range:InsertAfter(nTotSalary)
聽 聽
聽 聽END
聽 聽
聽 聽// Size columns, for simplicity, let word do the work
聽 聽:Columns:Autofit()
END
oWord:ActiveDocument:SaveAs("D:\Anser")
oWord:ActiveDocument:Close()
oWord:Quit()
MsgInfo("Finished")
Return
Screen Snapshot
Regards
Anser