Article technique

HotXLS: VBA payload and external link preservation in Delphi

Creez, modifiez, inspectez, calculez et exportez des classeurs Excel directement depuis Delphi ou C++Builder. HotXLS est une bibliotheque native Object Pascal pour XLS et XLSX, concue pour outils bureau, traitements par lots, rapports et generation de documents sans automatisation Microsoft Excel.

Cet article s'adresse à teams editing workbook content while preserving macro payloads and link relationships they do not own. Il traite VBA payload and external link preservation comme une ingénierie documentaire de production, et non comme un simple appel de composant.

Le risque pratique est que a workbook can save successfully while silently dropping VBA projects, changing link targets, or refreshing data connections against policy. Le flux doit donc produire un contrat écrit, des diagnostics observables et des fichiers de régression réalistes.

Décisions d'architecture

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

Parcours d'implémentation

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

Preuves de validation

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.

Notes d'implémentation en production

Traitez HotXLS: VBA payload and external link preservation in Delphi comme un contrat de service explicite autour des appels HotXLS, en séparant validation d'entrée, écriture du classeur, contrôle de sortie et preuves de support

  • Définir la source de données, les plages de cellules et le format de sortie avant de créer le classeur
  • Consigner le nombre de lignes, les feuilles, les avertissements et le chemin de sortie dans une trace relisible
  • Encapsuler les détails applicatifs dans des helpers testables plutôt que dans des événements UI
  • Rouvrir ou inspecter le fichier enregistré avant livraison à un autre système ou au client

Défaillances à répéter en test

  • Un SaveAs réussi ne prouve pas que le contrat métier est respecté
  • Polices, droits et paramètres régionaux peuvent différer entre serveur et poste de développement
  • Les journaux ne doivent exposer ni mots de passe, ni données client, ni liens internes

Exemple Delphi détaillé

L'exemple Delphi suivant montre une frontière de service pratique pour ce sujet, avec politiques, journalisation et validation dans une couche testable

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;

Liste de mise en production

  • 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