Technischer Artikel

HotXLS: streaming write and server batch jobs in Delphi

Erstellen, bearbeiten, pruefen, berechnen und exportieren Sie Excel-Arbeitsmappen direkt aus Delphi- oder C++Builder-Code. HotXLS ist eine native Object-Pascal-Bibliothek fuer XLS und XLSX, entwickelt fuer Desktop-Tools, Batchauftraege, Berichte und Dokumenterzeugung ohne Microsoft-Excel-Automatisierung.

Dieser Artikel richtet sich an teams producing many workbooks from services, schedulers, APIs, or report farms. Er behandelt streaming write and server batch jobs als produktive Dokumenttechnik und nicht als kurzen Komponentenaufruf.

Das praktische Risiko besteht darin, dass batch generation can overload memory, leave temporary files, retry unsafe stages, or hide partial output unless job boundaries are explicit. Deshalb braucht der Ablauf einen schriftlichen Vertrag, nachvollziehbare Diagnosen und reale Regressionsdateien.

Architekturentscheidungen

Treat every workbook as an isolated job. job identifier, output destination, retry policy, timeout, and cancellation behavior / temporary file location, cleanup, quota, and retention for failed workbooks

  • job identifier, output destination, retry policy, timeout, and cancellation behavior
  • temporary file location, cleanup, quota, and retention for failed workbooks
  • batch size, concurrency level, progress reporting, and back-pressure
  • which validation can run before final upload or delivery

Implementierungsablauf

Stream output only after validation checkpoints are defined. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  1. assign a job identifier and output boundary before opening the workbook writer
  2. prepare styles, sheets, and headers before streaming row data
  3. write rows in batches and checkpoint progress for operators
  4. validate size, sheet count, row count, and key formulas before final delivery
  5. clean or retain temporary files according to success, cancellation, or failure

Validierungsnachweise

Batch evidence for operators. Keep these fields with the output or support record.

  • job identifier, batch item count, row count, output size, elapsed time, and memory peak
  • stage timings for data load, workbook write, validation, save, and upload
  • temporary path, cleanup status, retry count, and cancellation reason
  • operator-facing failure reason and whether retry is safe

Streaming is a resource policy

Streaming write helps scale workbook generation, but it also limits which parts of the workbook can be revisited later. The job design should decide what must be known before streaming begins.

Implementierungshinweise für die Produktion

Behandle HotXLS: streaming write and server batch jobs 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 RunWorkbookBatch(const Jobs: TArray<TWorkbookJob>);
var
  Job: TWorkbookJob;
  JobResult: TWorkbookJobResult;
begin
  for Job in Jobs do
  begin
    StartJobAudit(Job.Id, Job.OutputFile);
    try
      RequireWritableDestination(Job.OutputFile);
      RequireTempQuota(Job.TempFolder, Job.ExpectedRows);
      JobResult := WriteWorkbookJob(Job);
      ValidateWorkbookForDelivery(JobResult.OutputFile, JobResult.ExpectedRows);
      CompleteJobAudit(Job.Id, JobResult);
    except
      on E: Exception do
      begin
        MarkJobFailed(Job.Id, E.Message, CanRetryWorkbookJob(Job));
        CleanupOrRetainTempFiles(Job, E);
        raise;
      end;
    end;
  end;
end;

function WriteWorkbookJob(const Job: TWorkbookJob): TWorkbookJobResult;
var
  Wb: TXLSXWorkbook;
  Sh: IXLSWorksheet;
begin
  Wb := TXLSXWorkbook.Create;
  try
    Sh := Wb.Sheets[0];
    Sh.Name := 'Batch Output';
    StreamRowsIntoWorksheet(Sh, Job.Reader, Job.Progress);
    WriteBatchMetricsSheet(Wb, Job);
    if Wb.SaveAs(Job.OutputFile) <> 1 then
      RaiseWorkbookSaveError(Job.OutputFile);
    Result := BuildWorkbookJobResult(Job);
  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