Page 1 of 1
Mail Merging a tStringGrid into a tRichView
Posted: Wed Oct 13, 2010 10:48 pm
by GerryD
I've reviewed the mail merge demos and I have some questions and am in need of some advice. In my application the mail merge template is provided by the customer as an RTF file with the appropriate field names tagged between []s. One of the fields I need to merge is a tStringGrid from one of my applications forms. A complication is I've taken over the CellDraw event for the tStrigGrid so the background color of the cell is a function of the text. So it's not a straight text merging problem.
What's the best way to get this data into a tRichView so I can print it? If I wanted to put two tStringGrids side by side in the document would it be best to use TextBoxs around them or maybe stick them into a two cell table?
Would it be easier just to grab the tStringGird canvas and merge in the data as graphics images?
Any recommendations would be appreciated.
Posted: Thu Oct 14, 2010 10:57 am
by Sergey Tkachenko
May be you can convert this string grid to a table (TRVTableItemInfo) with the proper colors of cells?
Posted: Fri Oct 15, 2010 2:25 am
by GerryD
So i went down this path. I can build a TRVTableItemInfo with the data from my StringGrid but I can't figure out how to insert it into my tRichView. Here's the snippet of code from the mail merge demo
FieldName := Copy(s, j+1, FieldEnd-j-1);
FieldValue := GetFieldValueFromDatabase(FieldName);
Delete(s, j, FieldEnd-j+1);
Insert(FieldValue, s, j);
Which I've turned into this for a simple test
FieldName := Copy(s, j+1, FieldEnd-j-1);
Delete(s, j, FieldEnd-j+1);
if FieldName = 'MyStringSridField' then
begin
// Build TRVTableItemInfo
atable := TRVTableItemInfo.CreateEx(3,3, RVData);
// Fill in the Cells
// Some uninteresting code
// How do I insert it???
end
else
begin
FieldValue := GetFieldValueFromDatabase(FieldName);
Insert(FieldValue, s, j);
end;
My table data doesn't show up in my Richedit. I can do a richedit.additem('',atable) and the data shows up but at the end of the document not where the mailmerge fieldname was.
Posted: Fri Oct 15, 2010 4:59 pm
by Sergey Tkachenko
http://www.trichview.com/support/files/ ... -text4.zip demo supports the following field values: text, picture, table.
Posted: Fri Oct 15, 2010 11:42 pm
by GerryD
Thanks. That's works great but it gets me back to one of my original questions.
" If I wanted to put two tStringGrids side by side in the document would it be best to use TextBoxs around them or maybe stick them into a two cell table?
So I tried the two cell table and it worked but I can't get Trichview to read my RTF template with Text Boxes. The texxtbox and the text inside isn't displayed. So I just tried a simple LoadRTF() with the same result.
Doesn't the latest version of tRichview support text boxes?
Posted: Sat Oct 16, 2010 11:53 am
by Sergey Tkachenko
Sorry, TRichView does not support floating objects in RTF, including text boxes.
Use a table with two cells.
Colum Widths in mail-merged tStringGrid
Posted: Wed May 11, 2011 11:31 pm
by GerryD
I'm finally getting back to this after a brief layoff.
So as I mentioned previously I'm getting the stringgrids place correctly on the page inside some table cells that describe the layout of the stringgrids relative to each other.
My new problem is that TRichView is automatically changing the widths of the columns to fit into the cells. Is there a way to change this behavior to keep the relative size of all the columns constant?
Posted: Thu May 12, 2011 6:07 pm
by Sergey Tkachenko
Sorry, I am not sure that I understand how you want to change/lock column sizes.
Can you explain with more details?