使用Delphi填写使用富文本(rtf)文件制作的表格模板

发布于 2024-11-26 12:58:05 字数 155 浏览 0 评论 0原文

我有一个 rtf(富文本格式)文件格式的表。

我想知道是否可以在运行时将不同的内容放入单元格中。

这是一个屏幕截图。一些空白字段需要填写值。

截图

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.

screenshot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我恋#小黄人 2024-12-03 12:58:05

您写了“需要编辑一些空白字段” - 如果这意味着 RTF 是某种模板,需要以编程方式填写空白字段,那么我会这样做:

  • 使用文本编辑器打开 RTF 文档(例如 OpenOffice 或 MS Word)
  • 在空字段中插入特殊占位符字符串,如 $field1$、$field2$ ...
  • 将文档保存
  • 在 Delphi 应用程序中,将 RTF 加载到字符串中(例如使用 TStringlist)
  • 使用 Delphi String查找和替换的函数带有实际值的特殊占位符字符串

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:

  • use your text editor to open the RTF document (OpenOffice or MS Word for example)
  • insert special placeholder strings in the empty fields like $field1$, $field2$ ...
  • save the document
  • in your Delphi application, load the RTF into a string (using TStringlist for example)
  • use Delphi String functions to find and replace the special placeholder strings with the actual values
删除→记忆 2024-12-03 12:58:05

要在一张纸上打印表格,只需在打印机的画布​​上绘图即可!

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;

结果:http://privat.rejbrand.se/sampledrawing.pdf

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

无人问我粥可暖 2024-12-03 12:58:05

要在 TRichEdit 中使用现有的 RTF 内容,请将其加载到组件的 Text 或 Lines 属性中:

RichEdit1.Lines.LoadFromFile(rtfFilename);

- 或 -

RichEdit1.Text := StringILoadedFromAnRtfFileOnDisk;

我不确定您想要做什么(根据某些现有的未指定 RTF 内容以编程方式创建或修改表格,打印它等)。通过询问丰富的编辑,还询问常规编辑,这是非常难以理解的。

您在评论中询问,如何在 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;

如果您想在上面显示的屏幕截图中使用 RTF 内容,在您的 delphi 程序中,只需加载它并尝试一些操作,然后提出一个具体问题。向我们展示 microsoft word 的屏幕截图并不能帮助您弄清楚您的问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文