Balanced columns (Delphi)
Overview
The FlexCel reporting engine will automatically balance the ranges that
are inside a master range so the master range will stay in place. You
can use this feature for creating master detail reports with balanced
columns inside (where the master will grow to cover the longest column),
or use a fake "master" report to ensure the columns inside the report
have the same number of rows.
Concepts
How to create a master detail report with detail columns, and where
the master grows with the biggest of the columns. In columns where
the number is less, the last cell of the column will be copied
to fill the missing rows, so all columns have the same height.
How to use Fixed N Bands to avoid having empty rows at the
end of each master record.
How to use the "ROWS" function in the config sheet (see
Creating empty datasets with N rows) to create a
database with a single row, that you can use as a master from the
main report, and so ensure balanced columns.
For more information in balanced columns please take a look at the
section Fixed N Bands in the Reports designer's guide.
Files
UMainForm.pas
unit UMainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
FlexCel.VCLSupport, FlexCel.Core, FlexCel.XlsAdapter, FlexCel.Report, FlexCel.Render,
{$if CompilerVersion >= 23.0} System.UITypes, {$IFEND}
ShellApi,
Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type
TMainForm = class(TForm)
btnCancel: TButton;
btnGo: TButton;
SaveDialog: TSaveDialog;
Label1: TLabel;
procedure btnCancelClick(Sender: TObject);
procedure btnGoClick(Sender: TObject);
private
procedure RunReport;
function GetDataPath: string;
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
uses IOUtils, DemoCustomers;
{$R *.dfm}
procedure TMainForm.btnCancelClick(Sender: TObject);
begin
Close;
end;
procedure TMainForm.btnGoClick(Sender: TObject);
begin
RunReport;
end;
function TMainForm.GetDataPath: string;
begin
Result := TPath.Combine(TPath.GetDirectoryName(ParamStr(0)), '..\..');
end;
procedure TMainForm.RunReport;
var
Report: TFlexCelReport;
begin
if not SaveDialog.Execute then exit;
Report := TFlexCelReport.Create(true);
try
Report.AddTable(DemoTables);
Report.SetValue('Date', Now);
Report.Run(
TPath.Combine(GetDataPath, 'Balanced Columns.template.xls'),
SaveDialog.FileName);
finally
Report.Free;
end;
if MessageDlg('Do you want to open the generated file?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
ShellExecute(0, 'open', PCHAR(SaveDialog.FileName), nil, nil, SW_SHOWNORMAL);
end;
end;
end.