DEFINE CLASS WordReport AS custom
Name = "WordReport"
TemplateFile = ''
ReportFile = ''
PROTECTED WordApplication
PROTECTED WordDocument
Reference = .F.
PROCEDURE create
LOCAL loApp, loDoc
loApp=THIS.WordApplication
loDoc=THIS.WordDocument
loDoc.SaveAs(THIS.ReportFile)
local lcFoundText, lcCommand
loApp.Selection.Find.Execute('\<*\>',,,.T.,,,.T.,1)
lcFoundText=loApp.Selection.Text
DO WHILE SUBSTR(lcFoundText,1,1)='<' AND ;
SUBSTR(lcFoundText,LEN(lcFoundText),1)='>'
lcCommand=loApp.Selection.Text
lcCommand=SUBSTR(lcCommand,1,LEN(lcCommand)-1)
lcCommand=SUBSTR(lcCommand,2)
loApp.Selection.Text=EVALUATE(lcCommand)
loApp.Selection.Find.Execute('\<*\>',,,.T.,,,.T.,1)
lcFoundText=loApp.Selection.Text
ENDDO
loDoc.Save()
ENDPROC
PROCEDURE show
LPARAMETERS nStyle
LOCAL loApp
loApp=this.WordApplication
loApp.Visible=.t.
ENDPROC
PROCEDURE hide
LOCAL loApp
loApp=THIS.WordApplication
loApp.Visible=.t.
ENDPROC
PROCEDURE print
LPARAMETERS cText
LOCAL loApp
loApp=THIS.WordApplication
IF loApp.Visible
loApp.Dialogs(88).Show()
ELSE
THIS.Show()
loApp.Dialogs(88).Show()
THIS.Hide()
ENDIF
ENDPROC
PROCEDURE reference_access
RETURN THIS.WordApplication
ENDPROC
PROCEDURE reference_assign
LPARAMETERS vNewVal
ENDPROC
PROCEDURE Init
LPARAMETERS lcTempaleName, lcReportName
THIS.TemplateFile=lcTempaleName
THIS.ReportFile=lcReportName
THIS.WordApplication=CREATEOBJECT('Word.Application')
LOCAL loApp
loApp=THIS.WordApplication
THIS.WordDocument=loApp.Documents.Open(THIS.TemplateFile)
ENDPROC
PROCEDURE Destroy
LOCAL loApp
loApp=THIS.WordApplication
loApp.Quit()
ENDPROC
ENDDEFINE
Suerte