Article technique

HotXLS: workbook metadata and document properties in Delphi

Cet article français présente HotXLS: workbook metadata and document properties in Delphi pour les équipes qui construisent des solutions avec Delphi, C++Builder, Lazarus/FPC et les composants losLab

L'accent est mis sur les choix pratiques, les pièges et les points de contrôle afin que la solution reste fiable en production

Décisions d'architecture

Own metadata as delivery data. standard properties such as title, subject, author, company, category, and keywords / custom properties needed for customer, job, retention, version, or workflow state

  • standard properties such as title, subject, author, company, category, and keywords
  • custom properties needed for customer, job, retention, version, or workflow state
  • whether metadata can expose personal data, internal IDs, or confidential notes
  • revision, generated-by, and template-version strategy

Parcours d'implémentation

Set properties from the business record. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  1. clear template metadata that should not reach generated output
  2. populate standard and custom properties from the business record
  3. validate required properties before saving or uploading the workbook
  4. include metadata in search or DMS hand-off checks
  5. audit final properties when support bundles are created

Preuves de validation

Metadata evidence for document management. Keep these fields with the output or support record.

  • standard property values, custom property names, and required-property status
  • template version, generator version, job identifier, and retention category
  • privacy review for metadata fields that may expose sensitive values
  • DMS or search-index acceptance result

Workbook metadata is visible outside Excel

Document properties are consumed by search indexes, records systems, portals, DMS workflows, and support staff. They should be generated deliberately rather than inherited accidentally from a designer's template file.

Notes d'implémentation en production

Traitez HotXLS: workbook metadata and document properties 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 StampWorkbookMetadata(const InputFile, OutputFile: string; const Props: TWorkbookDocumentProperties);
var
  Wb: TXLSXWorkbook;
  Cover: IXLSWorksheet;
begin
  RequireFileExists(InputFile);
  Wb := TXLSXWorkbook.Create;
  try
    Wb.Open(InputFile);
    ApplyDocumentProperties(Wb, Props);
    Cover := EnsureWorksheet(Wb, 'Document Info');
    Cover.Range['A1'].Value := 'Document owner';
    Cover.Range['B1'].Value := Props.Owner;
    Cover.Range['A2'].Value := 'Classification';
    Cover.Range['B2'].Value := Props.Classification;
    Cover.Range['A3'].Value := 'Retention profile';
    Cover.Range['B3'].Value := Props.RetentionProfile;
    Cover.Range['A1:B3'].ApplyBuiltinStyle(xbsGood);

    AssertMetadataPolicy(Wb, Props);
    WriteMetadataAudit(Wb, Props);

    if Wb.SaveAs(OutputFile) <> 1 then
      RaiseWorkbookSaveError(OutputFile);
  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

Exemples de code supplémentaires

var
  Legacy: IXLSWorkbook;     // reference-counted interface: no manual Free
begin
  Legacy := TXLSWorkbook.Create;
  if Legacy.Open('archive-1999.xls') <= 0 then
    raise Exception.Create('Cannot open archive file');

  Legacy.Title := 'FY1999 ledger (migrated copy)';
  Legacy.Author := 'Archive Migration Batch';
  Legacy.Company := 'Northwind Financial';
  Legacy.Comments := 'Migrated 2026-06-11; source retained in cold storage';
  Legacy.LastSavedBy := 'migration-svc';   // BIFF WRITEACCESS record

  Legacy.SaveAs('archive-1999-stamped.xls');
end;
var
  Book: TXLSXWorkbook;
begin
  Book := TXLSXWorkbook.Create;
  try
    if Book.Open(FileName) = 1 then
    begin
      Writeln(Format('%s | title="%s" author="%s" created=%s',
        [ExtractFileName(FileName), Book.Title, Book.Author,
         FormatDateTime('yyyy-mm-dd', Book.Created)]));
      if Book.Created = 0 then
        Writeln('  no creation date recorded');
    end;
  finally
    Book.Free;
  end;
end;