我正在使用报表生成器,并尝试使用报表生成器动态创建报表,因为有很多字段,所以我不想手动执行。代码的顶部起作用,但顶部的字段名称没有问题,但是它没有填充报表中的任何数据。我不知道是什么问题。
编辑:如果我将dbtext放到实际的报表组件上,则将其分配到填充的数据字段中,当我进入调试状态时,进入此功能,我可以看到它正在获取数据,但没有将其添加到报告。
procedure TfrmMainMkt.makeReport;
const
TmpEspacamento = 0.7;
StartTop = 0.1875;
AutoSize = True;
TmpWidth = 0.5;
var
I: Integer;
Txt: TppLabel;
DBTxt : TppDBText;
StartLeft: Double;
sFILENAME : string;
begin
StartLeft := 0;
sFILENAME := SetDirectoryForTSUser();
ppDBPipeline1.DataSource := DataSource1;
ppReport1.DataPipeline := ppDBPipeline1;
with DataSource1.DataSet do
begin
for i := 0 to DataSource1.DataSet.FieldCount - 1 do
begin
Txt := TppLabel.Create(ppReport1);
Txt.Caption := DataSource1.DataSet.Fields[i].FieldName ;
Txt.Left := StartLeft;
Txt.Top := StartTop;
Txt.Band := ppHeaderBand11;
Txt.AutoSize := AutoSize;
Txt.Width := TmpWidth;
Txt.Font := Font;
//Txt.TextAlignment := TextAlignment;
//Txt.Border := Border;
Txt.Transparent := true;
Txt.Tag := -50000;
StartLeft := TmpEspacamento + StartLeft;
end;
StartLeft := 0;
for i := 0 to DataSource1.DataSet.FieldCount - 1 do
begin
DBTxt := TppDBText.Create(self);
DBTxt.Parent := ppReport1;
DBTxt.DataField := DataSource1.DataSet.Fields[i].AsString;
DBTxt.DataPipeline := ppDBPipeline1;
DBTxt.ParentDataPipeline := true;
DBTxt.Left := StartLeft;
DBTxt.Top := StartTop;
DBTxt.DesignLayer := ppDesignLayer13;
DBTxt.Band := ppDetailBand12;
DBTxt.AutoSize := AutoSize;
DBTxt.Width := TmpWidth;
DBTxt.Font := Font;
//Txt.TextAlignment := TextAlignment;
//Txt.Border := Border;
DBTxt.Transparent := true;
DBTxt.Tag := -50000;
StartLeft := TmpEspacamento + StartLeft;
end;
end;
sFILENAME := sFILENAME + 'Report.xlsx';
// ppReport1.DeviceType := 'XLSXReport';
// ppReport1.TextFileName := sFILENAME;
// ppReport1.AllowPrintToFile := True;
ppReport1.Print
end;