Reputation: 653
I have a table in rtf (rich text format) file format.
I wonder if it is possible to place different content into the cells at runtime.
Here is a screenshot. Some blank fields need to be filled in with a value.
Upvotes: 1
Views: 4774
Reputation: 69114
To use existing RTF content in a TRichEdit, load it into the Text or Lines properties of the component:
RichEdit1.Lines.LoadFromFile(rtfFilename);
-or-
RichEdit1.Text := StringILoadedFromAnRtfFileOnDisk;
I am not sure what you want to do (programmatically create a or modify a table based on some existing unspecified RTF content, print it, etc). By asking about a rich edit, and also asking about a regular edit, it's very hard to understand.
You asked in a comment, how you can create tables in a TRichEdit:
procedure TForm1.PutTableIntoRichEdit;
begin
RichEdit1.Text := '{\rtf1\ansi\deff0'#13#10+
'\trowd'#13#10+
'\cellx1000'#13#10+
'\cellx2000'#13#10+
'\cellx3000'#13#10+
'cell 1\intbl\cell'#13#10+
'cell 2\intbl\cell'#13#10+
'cell 3\intbl\cell'#13#10+
'\row'#13#10+
'}' ;
end;
If you want to use that RTF content in the screenshot you showed above, inside your delphi program, just load it up and try something, and ask a specific question. Showing us a screenshot of microsoft word isn't helping your question be clear.
Upvotes: 2
Reputation: 109158
To print a form on a sheet of paper, simply draw on the printer's canvas!
procedure TForm1.Button1Click(Sender: TObject);
var
y, Margin, Col2: integer;
LineHeight: integer;
begin
with TPrintDialog.Create(nil) do
try
if not Execute then
Exit;
finally
Free;
end;
Printer.BeginDoc;
Printer.Title := 'Sample Form';
Printer.Canvas.Font.Name := 'Arial';
Printer.Canvas.Font.Size := 11;
Margin := 5*Printer.Canvas.TextWidth('M');
Col2 := 35*Printer.Canvas.TextWidth('M');
LineHeight := 3 * Printer.Canvas.TextHeight('M') div 2;
y := Margin;
Printer.Canvas.Font.Style := [fsBold];
Printer.Canvas.TextOut(MARGIN, y, 'Name: ');
Printer.Canvas.Font.Style := [];
Printer.Canvas.TextOut(Col2, y, 'Andreas Rejbrand');
inc(y, LineHeight);
Printer.Canvas.Font.Style := [fsBold];
Printer.Canvas.TextOut(MARGIN, y, 'Age: ');
Printer.Canvas.Font.Style := [];
Printer.Canvas.TextOut(Col2, y, '23');
inc(y, LineHeight);
Printer.Canvas.Font.Style := [fsBold];
Printer.Canvas.TextOut(MARGIN, y, 'Nationality: ');
Printer.Canvas.Font.Style := [];
Printer.Canvas.TextOut(Col2, y, 'Swedish');
Printer.EndDoc;
end;
The result: http://privat.rejbrand.se/sampledrawing.pdf
Upvotes: 3
Reputation: 36664
You wrote "Some blank fields need to be edited" - if this means that the RTF is some kind of template, where empty fields need to be filled in programmatically, here is what I would do:
Upvotes: 4