Articolo tecnico

HotXLS: defined names and cross-sheet formulas in Delphi

Crea, modifica, ispeziona, calcola ed esporta cartelle di lavoro Excel direttamente da Delphi o C++Builder. HotXLS e una libreria nativa Object Pascal per XLS e XLSX, progettata per strumenti desktop, batch, report e generazione documenti senza automazione Microsoft Excel.

Questo articolo è rivolto a teams generating analytical workbooks whose formulas must survive sheet movement, template changes, and user edits. Tratta defined names and cross-sheet formulas come ingegneria documentale di produzione, non come una semplice chiamata al componente.

Il rischio pratico è che cross-sheet formulas are fragile when workbook-level names, sheet-level names, external links, and range movement are not governed. Per questo il flusso richiede un contratto scritto, diagnostica osservabile e file di regressione realistici.

Decisioni architetturali

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

Percorso di implementazione

Resolve name scope before writing formulas. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  1. inventory existing names before adding generated names
  2. create stable names for generated ranges before writing dependent formulas
  3. qualify sheet-level names deliberately to avoid accidental workbook-level collisions
  4. update formulas after sheet insertion, deletion, or movement
  5. calculate and inspect formulas before delivering the workbook

Evidenze di validazione

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.

Note di implementazione per la produzione

Tratta HotXLS: defined names and cross-sheet formulas in Delphi come un contratto di servizio esplicito attorno alle chiamate HotXLS, separando validazione dell'input, scrittura della cartella, controllo dell'output ed evidenze di supporto

  • Definire origine dati, intervalli di celle e formato di output prima di creare la cartella
  • Registrare righe, fogli, avvisi e percorso di output in una prova verificabile
  • Incapsulare i dettagli applicativi in helper testabili invece che in eventi UI
  • Riaprire o ispezionare il file salvato prima di consegnarlo a un altro sistema o al cliente

Casi di errore da provare

  • Un SaveAs riuscito non prova che il contratto di business sia corretto
  • Font, permessi e impostazioni locali possono variare tra server e macchina di sviluppo
  • I log non devono esporre password, dati cliente o link interni

Esempio Delphi dettagliato

L'esempio Delphi seguente mostra un confine di servizio pratico per questo tema, mantenendo policy, logging e validazione in un livello testabile

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;

Checklist di produzione

  • 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

HotXLS Component