Dieser deutsche Artikel behandelt HotXLS: defined names and cross-sheet formulas 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
Use names as a stable formula interface. workbook-level versus sheet-level name scope / name syntax, collision handling, hidden names, and user-visible names
- workbook-level versus sheet-level name scope
- name syntax, collision handling, hidden names, and user-visible names
- formula references to generated ranges, moved sheets, and external workbooks
- recalculation policy after names or referenced ranges change
Implementierungsablauf
Resolve name scope before writing formulas. The order below keeps the workflow reviewable for Delphi and C++Builder teams.
- inventory existing names before adding generated names
- create stable names for generated ranges before writing dependent formulas
- qualify sheet-level names deliberately to avoid accidental workbook-level collisions
- update formulas after sheet insertion, deletion, or movement
- calculate and inspect formulas before delivering the workbook
Validierungsnachweise
Formula evidence for maintainable workbooks. Keep these fields with the output or support record.
- name, scope, visible state, target reference, and owner profile
- formula text, resolved references, calculation result, and error state
- external-link references and whether they were preserved, updated, or blocked
- name collisions and remediation actions
Names are API surfaces inside the workbook
Defined names create a contract between formulas, templates, and generated data. Managing scope and references deliberately makes workbooks easier to maintain than hard-coded cell addresses scattered across sheets.
Implementierungshinweise für die Produktion
Behandle HotXLS: defined names and cross-sheet formulas 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 BuildNamedFormulaWorkbook(const OutputFile: string; const Assumptions: TAssumptionSet);
var
Wb: TXLSXWorkbook;
Inputs: IXLSWorksheet;
Summary: IXLSWorksheet;
begin
Wb := TXLSXWorkbook.Create;
try
Inputs := Wb.Sheets[0];
Inputs.Name := 'Inputs';
Summary := AddWorksheet(Wb, 'Summary');
WriteAssumptionTable(Inputs, Assumptions);
DefineWorkbookName(Wb, 'TaxRate', 'Inputs!$B$2');
DefineWorkbookName(Wb, 'DiscountRate', 'Inputs!$B$3');
Summary.Range['A1'].Value := 'Net revenue';
Summary.Range['B1'].Value := '=GrossRevenue*(1-DiscountRate)*(1-TaxRate)';
AssertRequiredNames(Wb, ['TaxRate', 'DiscountRate', 'GrossRevenue']);
Wb.Calculate;
AssertFormulaRangeHasValues(Summary, 'B1:B1');
WriteFormulaDependencyAudit(Wb);
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
var
Book: IXLSWorkbook; // interface-counted: do not Free
Names: IXLSNames;
begin
Book := TXLSWorkbook.Create;
// assume a sheet named 'Data' already holds the detail rows
Names := Book.GetNames;
Names.Add('TaxRate', '0.08');
Names.Add('Helper', 'Data!$A$2:$A$100', False); // False = hidden from the Name Manager
// XLS formulas go through Value, with the '=' prefix
Book.Sheets[1].Cells.Item[2, 2].Value := '=SUM(Data!A2:A100)*TaxRate';
Book.SaveAs('model.xls');
end;// the calculation engine resolves names and cross-sheet references in-process
V := Book.Calculate('SUM(Data!D2:D100)*TaxRate');
if VarIsNumeric(V) then
Log('net total checks out: ' + FloatToStr(V));