Articolo tecnico

HotXLS: VBA payload and external link preservation 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 editing workbook content while preserving macro payloads and link relationships they do not own. Tratta VBA payload and external link preservation come ingegneria documentale di produzione, non come una semplice chiamata al componente.

Il rischio pratico è che a workbook can save successfully while silently dropping VBA projects, changing link targets, or refreshing data connections against policy. Per questo il flusso richiede un contratto scritto, diagnostica osservabile e file di regressione realistici.

Decisioni architetturali

Identify protected workbook assets before editing. whether macro-enabled workbooks are accepted, preserved, blocked, or converted / external link inventory, update policy, trusted domains, and refresh behavior

  • whether macro-enabled workbooks are accepted, preserved, blocked, or converted
  • external link inventory, update policy, trusted domains, and refresh behavior
  • which workbook edits are allowed without rewriting protected payloads
  • security warning, operator review, and audit-report requirements

Percorso di implementazione

Preserve opaque payloads unless policy says otherwise. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  1. inventory VBA projects, external links, data connections, and defined names before editing
  2. load worksheet data changes without executing or refreshing external content
  3. preserve opaque payloads where policy allows and mark blocked content clearly
  4. save in a format that supports the required payloads
  5. compare pre-save and post-save inventories before delivery

Evidenze di validazione

Preservation evidence for governed workbooks. Keep these fields with the output or support record.

  • macro presence, VBA project preservation status, and macro-enabled format decision
  • external link targets, trusted or blocked status, and refresh policy
  • payload inventory before and after save
  • operator decision for workbooks with governed content

Preservation is not execution

Preserving VBA payloads and external links means keeping workbook structures intact while clearly avoiding automatic trust or execution. The application should inventory what exists and decide what is allowed to change.

Note di implementazione per la produzione

Tratta HotXLS: VBA payload and external link preservation 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 UpdateLinkedWorkbookWithoutBreakingMacros(const InputFile, OutputFile: string; const Update: TWorkbookUpdate);
var
  Wb: TXLSXWorkbook;
  BeforeState: TMacroLinkInventory;
  AfterState: TMacroLinkInventory;
begin
  RequireFileExists(InputFile);
  Wb := TXLSXWorkbook.Create;
  try
    Wb.Open(InputFile);
    BeforeState := CaptureMacroAndLinkInventory(Wb);
    AssertAllowedExternalLinks(BeforeState, Update.AllowedLinkHosts);

    SetNamedValue(Wb, 'RefreshDate', Update.RefreshDate);
    FillNamedTable(Wb, 'DataRefreshRows', Update.Rows);
    Wb.Calculate;

    if Wb.SaveAs(OutputFile) <> 1 then
      RaiseWorkbookSaveError(OutputFile);

    AfterState := InspectMacroAndLinkInventory(OutputFile);
    AssertMacroModulesPreserved(BeforeState, AfterState);
    AssertExternalLinksPolicy(AfterState, Update.AllowedLinkHosts);
    WriteMacroLinkAudit(OutputFile, BeforeState, AfterState);
  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