Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RTF codes inside TEXTMERGE and full justification in VFP9

Status
Not open for further replies.

Eliott

Programmer
Nov 8, 2009
91
BA
Dear members,
I presume that most wanted feature in all VFP version is report design and look. Until now I have had a few minor problemsw with it but now I faced myself with a problem that I can't to solve. Shortly, I have a report that have introduction part like:
Code:
"Dear AAA,
This letter is to inform you that your membership account number XXX is closed for debt of YYY dollars, which was created because you did not return borrowed book number GGG, dated DD/MM/YYYY, in the duration of NNN days. For your records we give you insight all changes in the last 60 days."
Bellow is part of report divided into two columns (2 x 17 records changes) where are printed earlier issuance and borrowings of books. I made classic VFP9 report that works fine but looks ugly because I must to leave some presumed unknown space for data shaped as variables. Some printed data are short but some are pretty long and I thought about justification of text.
I planned to solve it with classic TEXTMERGE and (maybe) public variable that will appear on report:
Code:
SET TEXTMERGE TO memvar lcText ON NOSHOW
SET TEXTMERGE ON
\\Dear << variable1 >>
\\this letter is to inform you that your membership account number <<variable2>> is closed...
\\for debt of << variable3 >> ...
...
SET TEXTMERGE TO
SET TEXTMERGE OFF
but I need to make in bold variables and to full justify left and right margins of introduction text to get better look. I found some advice on Microsoft web pages with RTF codes but mentioned example doesn't function on my VFP9 (some error with general field, like illegal operation!?). Later I tried to direct data for report to Word document but I wasn't able to print Data section into two columns, like I did in VFP report ( sum, total, group also were unable to use). Is there some solution for this problem?
Thank you in advance for your opinions.

There is no good nor evil, just decisions and consequences.
 
Seems to me some kind of letter and mail merge you want to do here. It's unusual to use VFP reports for that.

Such a thing of course rather goes out by snail mail instead of email. But there is Word Mail merge for this and to embed table data there is Excel and you can embed an Excel table into a Word doc.

That's the direction I would go, which may mean a rewrite of parts of the report(s) you have. Having too little insight I can't overview what would be the best advice, but at least Office is a good basis for letters of any kind and going that route would make it a "future proof" solution, wouldn't it?

Bye, Olaf.
 
Hi Olaf,

thank you for your opinion, I appreciate it. I saw somewhere that somebody used RTF codes inside TEXTMERGE but I can't recall where it was and how mentioned guy did it. Sure, export data into Excel and OLE with Word document would be good direction for first half of this problem, but I don't know how to deal with two-columns displaying of data bellow intro-text? Customer wants that all information appears on one page, not flows on another one (save paper, save forest...)
Thank you again for your time and effort to help.

There is no good nor evil, just decisions and consequences.
 
Eliott

\pard\qj

should do the trick.

However may i suggest going a step further and, rather than hard code the text of the letter, create a documents table and keep the rtf in a memo field. Then you can allow the user (or yourself) to modify the letters using a screen such as the 'using the rich text control' example under activex controls in the vfp9 solution samples. To add a justify button to that screen put the following in the button's click code.


*!* thanks to Bo Durban for this
#define WM_USER 0x0400
#define PFM_ALIGNMENT 0x00000008
#define EM_SETPARAFORMAT (WM_USER + 71)
#define EM_SETTYPOGRAPHYOPTIONS (WM_USER + 202)
#define TO_ADVANCEDTYPOGRAPHY 1
#define PARAFORMAT2_SIZEOF 188

#define PFA_LEFT 1
#define PFA_RIGHT 2
#define PFA_CENTER 3
** PARAFORMAT2 alignment options
#define PFA_JUSTIFY 4 && New paragraph-alignment option 2.0


DECLARE long SendMessage IN WIN32API as SendMessageLong ;
Long, Long, Long, Long
DECLARE long SendMessage IN WIN32API as SendMessageStr ;
Long, Long, Long, String@

** Set advanced typography.
** This has to be enabled to support "Justified" alignment
SendMessageLong(thisform.olerTF.Hwnd,EM_SETTYPOGRAPHYOPTIONS, ;
TO_ADVANCEDTYPOGRAPHY,TO_ADVANCEDTYPOGRAPHY)

LOCAL lqPFM

** Define PARAFORMAT2 structure and set alignment mask and value
lqPFM = REPLICATE(0h00,PARAFORMAT2_SIZEOF)
lqPFM = STUFF(lqPFM, 1, 4, BINTOC(PARAFORMAT2_SIZEOF,"4rs"))
lqPFM = STUFF(lqPFM, 5, 4, BINTOC(PFM_ALIGNMENT,"4rs"))
lqPFM = STUFF(lqPFM, 25, 4, BINTOC(PFA_JUSTIFY,"2rs")) && alignment value

** Set alignment
SendMessageStr(thisform.olerTF.Hwnd,EM_SETPARAFORMAT,0,@lqPFM)


then use moxie ( to print the RTF on a report (because that will give you multi page RTF).



hth

Nigel
 
@Nigel: thank you man. I'll try both advices, yours and Olaf's, neither looks easy in my situation, but I hope to success.
Each new day I wonder myself where you guys "dig" such tips & tricks... it's nice to have this nice place and to hear other opinions. Thank you.

There is no good nor evil, just decisions and consequences.
 
RTF is just some codes, so there is no trickery involved in preparing seom RTF code in VFP, but you need to use the OLECONTROL in the report and the RTFControl.

With Word/Excel automation you can do the two column data part in an Excel sheet and embed the part of the excel sheet you want to display after the text inside Word.

a brief demonstration:
Code:
oWord  = CreateObject("Word.Application")
oExcel = CreateObject("Excel.Application")
Doevents Force

oExcel.Workbooks.Add()
oExcel.ActiveSheet.Cells(1,1).Value = "column1"
oExcel.ActiveSheet.Cells(1,2).Value = "column2"
oExcel.ActiveWorkbook.SaveAs("2colsheet_az.xls")
oExcel.Quit()
Doevents Force

oWord.Documents.Add()
oParagraph = oWord.ActiveDocument.Paragraphs.Add()
oParagraph.Range.InsertBefore("Dear AAA, ...")
oParagraph = oWord.ActiveDocument.Paragraphs.Add()
oParagraph.Range.Select
Doevents Force
oWord.Selection.InlineShapes.AddOLEObject("Excel.Sheet","2colsheet_az.xls",.F.,.F.)
oWord.visible = .T.

I just recorded a makro while adding an excel file to the word doc to find out the code needed is mainly "InlineShapes.AddOleObject(...).

REcording Makros is in general a great way to see what you need to program to do with Excel or Word or both, what you do with it by manually operating it.

Bye, Olaf.
 
@Olaf: wow, small and nice part of code. I'll give a try to your code and research what is there pro & contra.
Thanks.

There is no good nor evil, just decisions and consequences.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top