Welcome to Foxite.COM Community Weblog Sign in | Join | Help



RTF memo combined with other fields of a Table - into Word Report


RTF is a very useful tool in saving and preserving of formatting on images and text inside a memo field as I have shown in my Enhanced RTF tool.  Also speaking of that tool, I have used there commands I learned inside Foxite Archive in the printing of the current content of the RTF control.  However, a new question has been raised just last night on how to print said RTF content from the memo field together with with data from other more fields; using a VFP or Crystal Report engine.  For that, I will simply refer you to this link: http://fox.wikis.com/wc.dll?Wiki~MicrosoftRTFControl

Although what I will be showing now is how to preview or print the same (memo field + all other selected fields of a table), I chose automation in the process of generating report as that is what I am experimenting with these days.  

Here is the appearance of the sample attachment here:




Here is the preview of an output:





And creating a report using Microsoft Word is made possible by something like this:

*********************
oGenerateReport Method
*********************

LPARAMETERS lcAction
#DEFINE Enter loWord.Selection.TypeParagraph
#DEFINE PasteClipBoard loWord.Selection.Paste(_ClipText)
#DEFINE SelectLine loWord.Selection.EndKey()
#DEFINE ChangeFont loWord.Selection.Font.Name
#DEFINE ChangeFontSize loWord.Selection.Font.Size
#DEFINE BoldTrue loWord.Selection.Font.Bold = .T.
#DEFINE BoldFalse loWord.Selection.Font.Bold = .F.
#DEFINE UnderlineTrue loWord.Selection.Font.Underline = 1
#DEFINE UnderlineFalse loWord.Selection.Font.Underline = 0
#DEFINE wdFormatDocument 0


LOCAL lcFileRTF, lcRepDoc, lcFileDoc, loWord

* First save the content of the memo field to an rtf document

lcFileRTF = ADDBS(GETENV("TMP"))+SYS(3)+".rtf"
STRTOFILE(test.findings,lcFileRTF)


* Second, Save it into .doc format (temp doc)

lcFileDoc = ADDBS(GETENV("TMP"))+SYS(3)+".doc"
loWord = CREATEOBJECT("word.application")
loWord.Documents.Open(lcFileRTF)
loWord.ActiveDocument.Saveas(lcFileDoc,wdFormatDocument)
loWord.Quit(.T.)


* Then work on the other fields via automation, create a raw file for the temp report

lcRepDoc = ADDBS(GETENV("TMP"))+SYS(3)+".doc"

* Create an empty file

STRTOFILE('',lcRepDoc)
loWord = CREATEOBJECT("word.application")
loWord.Documents.Open(lcRepDoc)

* Immediately change its format into .doc

loWord.ActiveDocument.Saveas(lcRepDoc,wdFormatDocument)


* Change formatting

BoldTrue
ChangeFont = "Courier New"
ChangeFontSize = 12
_cliptext = PADR("Patient ID",20)+": "+ALLTRIM(patientid)
PasteClipBoard
Enter
_cliptext = PADR("Name of patient",20)+": "+ALLTRIM(patient)
PasteClipBoard
Enter
_ClipText = PADR("Age of patient",20)+": "+ALLTRIM(STR(age))
PasteClipBoard
Enter
_ClipText = PADR("Sex",20)+": "+IIF(sex=1,"MALE","FEMALE")
PasteClipBoard
Enter
Enter
UnderlineTrue
_ClipText = "Clinical Findings:"
PasteClipBoard
Enter
BoldFalse
UnderlineFalse


* Now get the content of temp doc where the RTF memo contents is and insert it here

loWord.Documents.Open(lcFileDoc)
loWord.Selection.WholeStory
loWord.Selection.Copy
loWord.ActiveDocument.Close
PasteClipBoard
Enter


* And insert the last field just for fun and to show that you really can place it anywhere

ChangeFontSize = 10
BoldTrue
loWord.Selection.ParagraphFormat.Alignment = 2  && wdAlignParagraphRight
_ClipText = "Date: "+DTOC(xdate)
PasteClipBoard


* Save it again for changes to take effect

loWord.ActiveDocument.Save()
loWord.Quit(.T.)


* Open or print it now

ShellExecute(0,lcAction,lcRepDoc,"","",1)


 

I hope that this sample will be useful to you as a guide on achieving the same on your end.  To further learn on how my sample works, get the sample here

Note:  You should extract the sample to c:\ssrtf2 for it to work outright.  If you will save it on another folder location, you should change the SET DEFAULT TO settings I placed in the load event of the sample form. 

Enjoy!


Published Tuesday, November 24, 2009 10:32 AM by sandstorm36
Filed Under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

What do you think?

(required) 
required 
(required)