如何从 TStringGrid 的内容创建 QuickReport

发布于 2024-09-09 01:30:39 字数 139 浏览 2 评论 0原文

我在 Windows 7 上使用 Delphi 7 和 QuickReports。通常 QuickReports 需要由查询生成的数据集,但我想根据 StringGrid 的内容制作报告,就好像 StringGrid 是查询结果的表示一样。

如何?

I'm using Delphi 7 and QuickReports on Windows 7. Normally QuickReports require a DataSet generated by a query, but I want to make a report from the contents of a StringGrid as though the StringGrid is a representation of the results of a query.

How?

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

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

发布评论

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

评论(2

我一向站在原地 2024-09-16 01:30:39

使用 QuickReport.OnNeedData 事件处理程序。它传递一个名为 MoreData(布尔值)的 var 参数;将其设置为 True 意味着它会再次被调用。将 QuickReport.DataSource 属性留空,并使用普通 TQRText 控件而不是 TQRDBText。

// CurrLine is an Integer. In your case, it can represent a row in the StringGrid.
procedure TPrintLogForm.QuickRep1NeedData(Sender: TObject;
                      var MoreData: Boolean);
begin
  MoreData := (CurrLine < StringGrid1.RowCount);
  if MoreData then
  begin
    qrTextLine.Caption := StringGrid1.Cells[0, CurrLine];
    qrTextData.Caption := StringGrid1.Cells[1, CurrLine];
    Inc(CurrLine);
  end;
end;

Use the QuickReport.OnNeedData event handler. It passes a var parameter called MoreData (a boolean); setting it to True means it gets called again. Leave the QuickReport.DataSource property blank, and use plain TQRText controls rather than TQRDBText.

// CurrLine is an Integer. In your case, it can represent a row in the StringGrid.
procedure TPrintLogForm.QuickRep1NeedData(Sender: TObject;
                      var MoreData: Boolean);
begin
  MoreData := (CurrLine < StringGrid1.RowCount);
  if MoreData then
  begin
    qrTextLine.Caption := StringGrid1.Cells[0, CurrLine];
    qrTextData.Caption := StringGrid1.Cells[1, CurrLine];
    Inc(CurrLine);
  end;
end;
享受孤独 2024-09-16 01:30:39

我假设列集在 StringGrid 中是固定的(并且在相应的 TClientDataSet 中)。分步说明:

  1. 将 TClientDataSet 拖放到表单上
  2. 双击 TClientDataSet,按键盘上的 INSERT 键添加一个新字段,为网格的每一列添加一个字段。示例:COL1,字符串,128 宽度。
  3. 右键单击表单上的 TClientDataSet,然后
  4. 在运行时单击“创建数据集”运行此类代码:
  CS.Append;
  CS['COL1'] := 'Whatever';
  CS['COL2'] := 'An other thing';
  CS.Post;

您需要在循环中执行 Append/Post,循环遍历网格中的每一行。您可以在其他循环中分配 COL1、COL2 等,也可以手动编码。

I assume the set of columns is fixed within the StringGrid (and withing the corresponding TClientDataSet). Step-by-step instructions:

  1. Drop a TClientDataSet on the form
  2. Doublic-click on the TClientDataSet, hit the INSERT key on the keyboard to add an new field, add one field for each of your grid's columns. Example: COL1, String, 128 width.
  3. Right-click on the TClientDataSet on the form and hit "Create DataSet"
  4. AT RUNTIME run this kind of code:
  CS.Append;
  CS['COL1'] := 'Whatever';
  CS['COL2'] := 'An other thing';
  CS.Post;

You'll need to do the Append/Post in a loop, looping over each row in the grid. You can assign the COL1, COL2 etc in an other loop, or you can hand-code it.

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