Article technique

HotXLS: sheet listing and lightweight workbook inspection

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 that need fast workbook triage before loading formulas, styles, and cell data. Il traite sheet listing and lightweight workbook inspection comme une ingénierie documentaire de production, et non comme un simple appel de composant.

Le risque pratique est que opening full workbook content just to list sheets wastes time and memory, and it can expose unsupported features too late in the process. Le flux doit donc produire un contrat écrit, des diagnostics observables et des fichiers de régression réalistes.

Décisions d'architecture

Inspect package facts before full parsing. which facts are required before full workbook load / handling for hidden sheets, very hidden sheets, chart sheets, and unsupported sheet types

  • which facts are required before full workbook load
  • handling for hidden sheets, very hidden sheets, chart sheets, and unsupported sheet types
  • maximum package size, sheet count, and intake timeout
  • routing rules for files that only need metadata versus full calculation

Parcours d'implémentation

Use sheet inventory as an intake gate. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  1. open the workbook in an inspection path that avoids unnecessary cell materialization
  2. read format, package metadata, sheet list, visibility, and rough dimensions
  3. classify the workbook as preview, audit, convert, reject, or full-load
  4. show sheet inventory to operators when routing depends on workbook structure
  5. log inspection facts before deeper processing mutates state

Preuves de validation

Inspection evidence for routing decisions. Keep these fields with the output or support record.

  • format, file size, sheet count, sheet order, visibility, and sheet type
  • metadata such as creator, modified time, and application when available
  • routing result and reason based on lightweight facts
  • warnings for encrypted, damaged, macro-enabled, or oversized packages

Triage should be cheap and trustworthy

A lightweight inspection step should capture workbook format, sheet names, visibility, order, types, dimensions when available, and package-level warnings. That information is enough to route many files before deep processing.

Notes d'implémentation en production

Traitez HotXLS: sheet listing and lightweight workbook inspection 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 WriteWorkbookInspectionIndex(const SourceFile, OutputFile: string);
var
  Wb: TXLSXWorkbook;
  IndexSheet: IXLSWorksheet;
  Sh: IXLSWorksheet;
  SheetIndex: Integer;
  RowIndex: Integer;
begin
  RequireFileExists(SourceFile);
  Wb := TXLSXWorkbook.Create;
  try
    Wb.Open(SourceFile);
    IndexSheet := AddWorksheet(Wb, 'Inspection Index');
    WriteHeaderRow(IndexSheet, ['No', 'Sheet', 'UsedRange', 'FormulaCells', 'Warnings']);

    RowIndex := 2;
    for SheetIndex := 0 to Wb.Sheets.Count - 1 do
    begin
      Sh := Wb.Sheets[SheetIndex];
      IndexSheet.Range['A' + IntToStr(RowIndex)].Value := SheetIndex + 1;
      IndexSheet.Range['B' + IntToStr(RowIndex)].Value := Sh.Name;
      IndexSheet.Range['C' + IntToStr(RowIndex)].Value := GetUsedRangeAddress(Sh);
      IndexSheet.Range['D' + IntToStr(RowIndex)].Value := CountFormulaCells(Sh);
      IndexSheet.Range['E' + IntToStr(RowIndex)].Value := BuildSheetWarnings(Sh);
      Inc(RowIndex);
    end;

    AddAutoFilterToHeader(IndexSheet, 'A1:E' + IntToStr(RowIndex - 1));
    WriteInspectionAudit(Wb, SourceFile, RowIndex - 2);

    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