Technisch artikel

HotXLS: streaming write and server batch jobs in Delphi

Maak, bewerk, inspecteer, bereken en exporteer Excel-workbooks rechtstreeks vanuit Delphi- of C++Builder-code. HotXLS is een native Object Pascal-spreadsheetbibliotheek met broncode voor XLS- en XLSX-workflows, ontworpen voor desktoptools, batchtaken, rapportagesystemen en server-side documentgeneratie zonder Microsoft Excel-automatisering.

Dit artikel is bedoeld voor teams producing many workbooks from services, schedulers, APIs, or report farms. Het behandelt streaming write and server batch jobs als productiegerichte documentengineering, niet als een losse componentaanroep.

Het praktische risico is dat batch generation can overload memory, leave temporary files, retry unsafe stages, or hide partial output unless job boundaries are explicit. Daarom heeft de workflow een geschreven contract, observeerbare diagnose en representatieve regressiebestanden nodig.

Architectuurbeslissingen

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

Implementatiepad

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

Validatiebewijs

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.

Implementatienotities voor productie

Behandel HotXLS: streaming write and server batch jobs in Delphi als een expliciet servicecontract rond de HotXLS-aanroepen, met gescheiden invoercontrole, werkmapopbouw, uitvoercontrole en supportbewijs

  • Leg gegevensbron, celbereiken en uitvoerformaat vast voordat de werkmap wordt gemaakt
  • Log rijenaantal, bladen, waarschuwingen en uitvoerpad in controleerbaar supportbewijs
  • Plaats applicatiespecifieke details in testbare helpers in plaats van UI-events
  • Open of inspecteer het opgeslagen bestand voordat het naar een ander systeem of klant gaat

Foutscenario's om te oefenen

  • Een geslaagde SaveAs bewijst niet dat het zakelijke contract klopt
  • Lettertypen, rechten en regionale instellingen kunnen verschillen tussen server en ontwikkelmachine
  • Logs mogen geen wachtwoorden, klantgegevens of interne links onthullen

Uitgebreid Delphi-voorbeeld

Het volgende Delphi-voorbeeld toont een praktische servicegrens voor dit onderwerp en houdt beleid, logging en validatie testbaar gescheiden

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;

Productiechecklist

  • 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