Technischer Artikel

HotXLS Component: Office-free workbook automation in Delphi

Dieser deutsche Artikel behandelt HotXLS Component: Office-free workbook automation 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

Remove desktop Office from the runtime contract. supported input and output formats such as XLS, XLSX, ODS, CSV, and HTML / template ownership, calculation expectations, and formatting policy

  • supported input and output formats such as XLS, XLSX, ODS, CSV, and HTML
  • template ownership, calculation expectations, and formatting policy
  • service account permissions, file locking, concurrency, and temporary storage
  • verification steps used instead of opening Excel during generation

Implementierungsablauf

Build workbook output as application logic. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  1. inventory existing COM automation behavior before replacing it
  2. move workbook generation into a service layer with explicit profiles
  3. load templates, fill data, calculate, validate, and save without launching Excel
  4. run output checks with workbook-level diagnostics and representative files
  5. deploy with file-system and service permissions tested under the real account

Validierungsnachweise

Automation evidence for deployment. Keep these fields with the output or support record.

  • automation profile, template version, input format, output format, and calculation mode
  • service identity, output path, temporary storage, concurrency level, and elapsed time
  • warnings for unsupported Excel automation behaviors that were not replicated
  • open or validation result in target downstream applications

No Excel process means fewer surprises, not fewer decisions

Office-free automation avoids desktop session, COM, and installed Office dependencies. The application still needs to own workbook formats, calculation strategy, file locking, templates, and output verification.

Implementierungshinweise für die Produktion

Behandle HotXLS Component: Office-free workbook automation 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 BuildNightlyWorkbookWithoutExcel(const OutputFile: string; const ReportDate: TDate);
var
  Wb: TXLSXWorkbook;
  Summary: IXLSWorksheet;
  Detail: IXLSWorksheet;
begin
  Wb := TXLSXWorkbook.Create;
  try
    Summary := Wb.Sheets[0];
    Summary.Name := 'Summary';
    Detail := AddWorksheet(Wb, 'Detail');

    WriteReportHeader(Summary, 'Nightly Operations', ReportDate);
    WriteSummaryMetrics(Summary, LoadSummaryMetrics(ReportDate));
    WriteDetailRows(Detail, LoadDetailRows(ReportDate));
    LinkSummaryToDetail(Summary, Detail);
    Wb.Calculate;

    ValidateServerEnvironment(['fonts', 'temp-path', 'write-access']);
    WriteAutomationAudit(Wb, 'no-excel-automation', ReportDate);

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

Mem := TMemoryStream.Create;
Book := TXLSXWorkbook.Create;
try
  Sheet := Book.Sheets.Add('Data');
  Sheet.Cells[1, 1].Value := 'Generated ' + DateTimeToStr(Now);
  Book.SaveAs(Mem);          // writes from the CURRENT stream position
  Mem.Position := 0;         // rewind before handing the stream over
  Response.ContentType :=
    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
  Response.ContentStream := Mem;   // the framework now owns Mem
finally
  Book.Free;
end;
SheetX.Cells[1, 1].Value := 1200;
SheetX.Cells[2, 1].Value := 950;
SheetX.Cells[3, 1].Formula := 'SUM(A1:A2)';   // XLSX facade: no '=' prefix
Total := BookX.Calculate('SUM(A1:A2)');       // evaluate on the server, now
if Total <> 2150 then
  raise Exception.Create('reconciliation failed before delivery');