Technischer Artikel

HotXLS: workbook audit and conversion workbench in Delphi

Dieser deutsche Artikel behandelt HotXLS: workbook audit and conversion workbench in Delphi für Teams, die mit Delphi, C++Builder, Lazarus/FPC und losLab-Komponenten arbeiten

Der Fokus liegt auf praxisnahen Entscheidungen, Fallstricken und Prüfpunkten, damit die Lösung im produktiven Einsatz verlässlich bleibt

Architekturentscheidungen

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

Implementierungsablauf

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

Validierungsnachweise

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.

Implementierungshinweise für die Produktion

Behandle HotXLS: workbook audit and conversion workbench in Delphi als klaren Servicevertrag rund um die HotXLS-Aufrufe, mit getrennten Schritten für Eingabeprüfung, Arbeitsmappenaufbau, Ausgabekontrolle und Support-Evidenz

  • Datenquelle, Zellbereiche und Ausgabeformat festlegen, bevor die Arbeitsmappe erzeugt wird
  • Zeilenanzahl, Blattanzahl, Warnungen und Ausgabepfad in ein prüfbares Support-Protokoll schreiben
  • Anwendungsspezifische Details in testbare Helper kapseln, statt sie in UI-Ereignissen zu verteilen
  • Die gespeicherte Datei erneut öffnen oder prüfen, bevor sie an ein anderes System oder an Kunden geht

Fehlerfälle, die getestet werden sollten

  • Ein erfolgreicher SaveAs-Aufruf beweist noch nicht, dass der fachliche Vertrag stimmt
  • Schriftarten, Rechte und regionale Einstellungen können auf Servern anders sein als auf Entwicklerrechnern
  • Logs dürfen keine Passwörter, Kundendaten oder internen Links offenlegen

Ausführliches Delphi-Beispiel

Das folgende Beispiel zeigt eine praktische Servicegrenze für dieses Thema und hält Policy, Logging und Validierung testbar getrennt

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;

Produktionscheckliste

  • 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

Zusätzliche Codebeispiele

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;