Dieser deutsche Artikel behandelt HotXLS Component: template-based report generation in Delphi für Teams, die mit Delphi, C++Builder, Lazarus/FPC und losLab-Komponenten arbeiten
Der Fokus liegt auf praxisnahen Entscheidungen, Fallstricken und Prüfpunkten, damit die Lösung im produktiven Einsatz verlässlich bleibt
Architekturentscheidungen
Make templates part of the application interface. placeholder syntax, required values, repeated regions, and named-range ownership / style preservation, formula refresh, merged-cell behavior, and row insertion rules
- placeholder syntax, required values, repeated regions, and named-range ownership
- style preservation, formula refresh, merged-cell behavior, and row insertion rules
- localization of labels, number formats, dates, and sheet names
- template versioning, approval, rollback, and compatibility with old data profiles
Implementierungsablauf
Bind placeholders to typed data contracts. The order below keeps the workflow reviewable for Delphi and C++Builder teams.
- validate template version and required placeholders before loading data
- bind typed data to named ranges or placeholder regions
- expand repeating sections while preserving formulas, styles, merges, and page breaks
- calculate and validate key cells after data insertion
- store template version and placeholder results with the generated workbook
Validierungsnachweise
Template evidence that speeds up support. Keep these fields with the output or support record.
- template version, data profile, placeholder list, and missing-placeholder warnings
- expanded region sizes, inserted rows, formula refresh status, and style preservation
- localized label set and number-format profile
- regression workbook comparison against approved samples
A template is executable design
A workbook template carries layout, formatting, formulas, and business assumptions. The code should treat placeholders, named ranges, and repeating regions as a documented contract rather than free-form cell addresses.
Implementierungshinweise für die Produktion
Behandle HotXLS Component: template-based report generation in Delphi als klaren Servicevertrag rund um die HotXLS-Aufrufe, mit getrennten Schritten für Eingabeprüfung, Arbeitsmappenaufbau, Ausgabekontrolle und Support-Evidenz
- Datenquelle, Zellbereiche und Ausgabeformat festlegen, bevor die Arbeitsmappe erzeugt wird
- Zeilenanzahl, Blattanzahl, Warnungen und Ausgabepfad in ein prüfbares Support-Protokoll schreiben
- Anwendungsspezifische Details in testbare Helper kapseln, statt sie in UI-Ereignissen zu verteilen
- Die gespeicherte Datei erneut öffnen oder prüfen, bevor sie an ein anderes System oder an Kunden geht
Fehlerfälle, die getestet werden sollten
- Ein erfolgreicher SaveAs-Aufruf beweist noch nicht, dass der fachliche Vertrag stimmt
- Schriftarten, Rechte und regionale Einstellungen können auf Servern anders sein als auf Entwicklerrechnern
- Logs dürfen keine Passwörter, Kundendaten oder internen Links offenlegen
Ausführliches Delphi-Beispiel
Das folgende Beispiel zeigt eine praktische Servicegrenze für dieses Thema und hält Policy, Logging und Validierung testbar getrennt
procedure GenerateReportFromTemplate(const TemplateFile, OutputFile: string; const Context: TReportContext);
var
Wb: TXLSXWorkbook;
begin
RequireFileExists(TemplateFile);
Wb := TXLSXWorkbook.Create;
try
Wb.Open(TemplateFile);
EnsureTemplateVersion(Wb, Context.TemplateVersion);
SetNamedValue(Wb, 'ReportTitle', Context.Title);
SetNamedValue(Wb, 'ReportPeriod', Context.PeriodText);
FillNamedTable(Wb, 'RevenueRows', Context.RevenueRows);
FillNamedTable(Wb, 'ExpenseRows', Context.ExpenseRows);
Wb.Calculate;
AssertNoUnresolvedTemplateMarkers(Wb);
AssertRequiredSheetsVisible(Wb, ['Cover', 'Summary', 'Detail']);
WriteGenerationAudit(Wb, Context);
if Wb.SaveAs(OutputFile) <> 1 then
RaiseWorkbookSaveError(OutputFile);
finally
Wb.Free;
end;
end;
Produktionscheckliste
- Run the workflow on an empty workbook, a normal customer workbook, and a worst-case workbook
- Open the output with the target spreadsheet application or downstream importer
- Log product version, template version, profile, row count, output path, elapsed time, and warning count
- Keep passwords, temporary files, customer data, and support bundles under explicit retention rules
- Add regression workbooks when a customer file exposes a new edge case
Product documentation
Zusätzliche Codebeispiele
const
DetailRow = 10; // the formatted sample row in the template
var
I: Integer;
begin
// Open space before the totals block first, so the SUM range
// below the detail band stretches together with the data.
if Length(Items) > 1 then
Sheet.InsertRows(DetailRow + 1, Length(Items) - 1);
for I := 0 to High(Items) do
begin
if I > 0 then // clone styles + formulas from the sample row
Sheet.CopyRange(DetailRow, 1, DetailRow, 5, DetailRow + I, 1);
Sheet.Cells[DetailRow + I, 1].Value := Items[I].Name;
Sheet.Cells[DetailRow + I, 2].Value := Items[I].Qty;
Sheet.Cells[DetailRow + I, 3].Value := Items[I].UnitPrice;
Sheet.Cells[DetailRow + I, 4].Formula :=
Format('B%d*C%d', [DetailRow + I, DetailRow + I]); // no '=' prefix
end;
end;var
Total: Variant;
LastDetail: Integer;
begin
LastDetail := DetailRow + Length(Items) - 1;
Total := Book.Calculate(Format('SUM(Invoice!D%d:D%d)',
[DetailRow, LastDetail]));
if (not VarIsNumeric(Total)) or
(Abs(Total - ExpectedTotal) > 0.005) then
raise Exception.Create('Invoice total does not match the order record');
if Book.SaveAs('invoice-2026-0611.xlsx') <> 1 then
raise Exception.Create('Save failed: check output path and permissions');
end;