File Printing From Report Preview
Using:
Delphi 6
RB 6+
I have a need to print to a file from a TppReport.Viewer. Setting
'AllowPrintToFile' to true for the report allows for the user to set the
file name in the PrintDialog, but I am getting a blank file.
I have tried the following code (triggered by the closing of the
PrintDialog), but it isn't working:
procedure TCustomGridToReport.PrintDialogClose(Sender: TObject);
var
i: Integer;
begin
if (TppCustomReport(Sender).PrintDialog.TextFileName <> '') then begin //
textfilename is getting set correctly
FppReport.DeviceType := dtTextFile;
FppReport.TextFileType := ftComma;
FppReport.DetailBand.Save := True;
for i := 0 to FppReport.DetailBand.ObjectCount - 1 do
FppReport.DetailBand.AddSave(FppReport.DetailBand.Objects[i]);
end;
end;
I have also tried creating the TppPrintToFileSetupDialog on-the-fly in the
PrintDialogClose, but I cannot get the band information for the report to
show up in it. I really don't want to do it this way, because I don't want
the user to have to determine which information to save to the file. They
already have before they even got to the Preview screen.
Thanks in advance for the solution to my problem.
Tracy Jenkins
Delphi 6
RB 6+
I have a need to print to a file from a TppReport.Viewer. Setting
'AllowPrintToFile' to true for the report allows for the user to set the
file name in the PrintDialog, but I am getting a blank file.
I have tried the following code (triggered by the closing of the
PrintDialog), but it isn't working:
procedure TCustomGridToReport.PrintDialogClose(Sender: TObject);
var
i: Integer;
begin
if (TppCustomReport(Sender).PrintDialog.TextFileName <> '') then begin //
textfilename is getting set correctly
FppReport.DeviceType := dtTextFile;
FppReport.TextFileType := ftComma;
FppReport.DetailBand.Save := True;
for i := 0 to FppReport.DetailBand.ObjectCount - 1 do
FppReport.DetailBand.AddSave(FppReport.DetailBand.Objects[i]);
end;
end;
I have also tried creating the TppPrintToFileSetupDialog on-the-fly in the
PrintDialogClose, but I cannot get the band information for the report to
show up in it. I really don't want to do it this way, because I don't want
the user to have to determine which information to save to the file. They
already have before they even got to the Preview screen.
Thanks in advance for the solution to my problem.
Tracy Jenkins
This discussion has been closed.
Comments
Here is how to do it:
procedure TCustomGridToReport.PrintDialogClose(Sender: TObject);
var
iBand, iObj: Integer;
lComponent: TppCustomText;
begin
if (TppCustomReport(Sender).PrintDialog.TextFileName <> '') then begin
FppReport.DeviceType := dtTextFile;
FppReport.TextFileType := ftComma;
for iBand := 0 to FppReport.BandCount - 1 do begin
for iObj := 0 to FppReport.Bands[iBand].ObjectCount - 1 do
if (FppReport.Bands[iBand].Objects[iObj] is TppCustomText) and
not((iBand = 0) and (iObj = 0)) then begin // check to eliminate
the title from the file
lComponent := TppCustomText(FppReport.Bands[iBand].Objects[iObj]);
lComponent.Save := true;
lComponent.SaveOrder := iObj;
end;
FppReport.Bands[iBand].Save := True;
end;
end;
end;