Article technique

HotXLS: workbook audit and conversion workbench in Delphi

Cet article français présente HotXLS: workbook audit and conversion workbench 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

Audit before converting. conversion targets such as XLSX, XLS, ODS, CSV, HTML, or PDF-like reports / macro, external-link, hidden-sheet, protection, and formula policies

  • conversion targets such as XLSX, XLS, ODS, CSV, HTML, or PDF-like reports
  • macro, external-link, hidden-sheet, protection, and formula policies
  • feature preservation versus flattening versus blocking
  • operator review states, warnings, and retained audit reports

Parcours d'implémentation

Use a feature inventory to choose conversion policy. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  1. open the workbook in audit mode and inventory sheets, metadata, formulas, links, and macros
  2. classify features into safe, warn, convert, preserve, or block
  3. show the operator a concise risk summary before conversion
  4. run the conversion with a named profile and capture feature-loss warnings
  5. compare key cells and workbook structure after conversion

Preuves de validation

Audit evidence for conversion decisions. Keep these fields with the output or support record.

  • source format, sheet list, hidden-sheet count, macro presence, and external-link count
  • formula, chart, image, protection, validation, and defined-name summary
  • conversion profile, warning list, dropped-feature list, and output hash
  • operator decision and support report path

Conversion is a risk decision, not only a file save

A workbench should show what the workbook contains before converting it. Operators need to know whether macros, links, hidden content, formulas, charts, or protection change the acceptable path.

Notes d'implémentation en production

Traitez HotXLS: workbook audit and conversion workbench 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 ConvertWorkbookWithAudit(const InputFile, OutputFile: string; const Profile: TConversionProfile);
var
  Wb: TXLSXWorkbook;
  BeforeState: TWorkbookInventory;
  AfterState: TWorkbookInventory;
begin
  RequireFileExists(InputFile);
  Wb := TXLSXWorkbook.Create;
  try
    Wb.Open(InputFile);
    BeforeState := CaptureWorkbookInventory(Wb);
    ApplyConversionProfile(Wb, Profile);
    WriteConversionAuditSheet(Wb, BeforeState, Profile);

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

    AfterState := InspectSavedWorkbook(OutputFile);
    AssertConversionResult(BeforeState, AfterState, Profile.RequiredSignals);
    ArchiveConversionEvidence(InputFile, 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

Exemples de code supplémentaires

var
  Book: TXLSXWorkbook;
  Sheet: TXLSXWorksheet;
  I: Integer;
begin
  Book := TXLSXWorkbook.Create;
  try
    if Book.Open(FileName) <> 1 then Exit;
    for I := 0 to Book.Sheets.Count - 1 do
    begin
      Sheet := Book.Sheets[I];
      Writeln(Format('%s: cells=%d merges=%d charts=%d cf=%d dv=%d protected=%s',
        [Sheet.Name, Sheet.Cells.Count, Sheet.MergedCells.Count,
         Sheet.Charts.Count, Sheet.ConditionalFormats.Count,
         Sheet.DataValidations.Count, BoolToStr(Sheet.IsProtected, True)]));
    end;
    if Book.HasVbaProject then
      Writeln('  contains VBA project - macro policy applies');
    if Book.ExternalLinks.Count > 0 then
      Writeln(Format('  %d external link(s)', [Book.ExternalLinks.Count]));
  finally
    Book.Free;
  end;
end;
var
  Legacy: IXLSWorkbook;        // interface reference: do not Free
  Modern: TXLSXWorkbook;
begin
  if SameText(ExtractFileExt(FileName), '.xls') then
  begin
    Legacy := TXLSWorkbook.Create;
    if Legacy.Open(FileName) <= 0 then Exit;
    if SaveXLSWorkbookAsXLSX(Legacy,
         ChangeFileExt(FileName, '.xlsx')) <= 0 then
      Writeln('bridge failed: ' + FileName);
  end
  else
  begin
    Modern := TXLSXWorkbook.Create;
    try
      Modern.StreamingWrite := True;     // stream sheet XML into the zip
      if Modern.Open(FileName) = 1 then
        Modern.SaveAsCSV(ChangeFileExt(FileName, '.csv'), 0, ',');
    finally
      Modern.Free;
    end;
  end;
end;