Teknisk artikel

HotXLS Component: ODS open, save, and round-trip in Delphi

Skapa, redigera, granska, beräkna och exportera Excel-arbetsböcker direkt från Delphi- eller C++Builder-kod. HotXLS är ett nativt Object Pascal-bibliotek med källkod för XLS- och XLSX-flöden, avsett för skrivbordsverktyg, batchjobb, rapportsystem och serversidig dokumentgenerering utan Microsoft Excel-automatisering.

Den här artikeln är skriven för teams accepting OpenDocument Spreadsheet files while still producing Excel-compatible workflows. Den behandlar ODS open, save, and round-trip som produktionsnära dokumentteknik, inte som ett isolerat komponentanrop.

Den praktiska risken är att round-trip support can preserve values but still lose formulas, styles, charts, or page settings when feature gaps are not reported. Därför behöver flödet ett skrivet kontrakt, observerbar diagnostik och realistiska regressionsfiler.

Arkitekturbeslut

Classify ODS compatibility before editing. accepted ODS sources, supported feature set, and blocked feature categories / formula, style, chart, image, conditional formatting, and page setup handling

  • accepted ODS sources, supported feature set, and blocked feature categories
  • formula, style, chart, image, conditional formatting, and page setup handling
  • save format after editing and whether the user expects ODS or XLSX output
  • warning policy for unsupported or approximated features

Implementeringsflöde

Track what is preserved, converted, or dropped. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  1. inspect the ODS package and create a feature inventory before editing
  2. map sheets, cells, formulas, styles, images, and charts to supported workbook objects
  3. apply edits while preserving original intent where possible
  4. save output in the chosen format and compare key sheets with the source
  5. attach a compatibility report when features are converted or dropped

Valideringsbevis

Round-trip evidence for customer trust. Keep these fields with the output or support record.

  • source format, sheet count, formula count, style count, chart count, and image count
  • preserved, converted, approximated, and dropped feature counts
  • output format, warning summary, and key-cell comparison
  • viewer compatibility notes for LibreOffice and Excel when relevant

OpenDocument and Excel models overlap but differ

ODS support should identify which workbook features map cleanly, which require conversion, and which need warnings. A professional workflow gives users evidence instead of pretending every spreadsheet model is identical.

Implementeringsanteckningar för produktion

Behandla HotXLS Component: ODS open, save, and round-trip in Delphi som ett tydligt servicekontrakt runt HotXLS-anropen, med separerad indatavalidering, arbetsboksskrivning, utdata kontroll och supportbevis

  • Bestäm datakälla, cellområden och utdataformat innan arbetsboken skapas
  • Logga rader, blad, varningar och utdata sökväg i granskningsbar supportevidens
  • Kapsla applikationsdetaljer i testbara helpers i stället för UI-händelser
  • Öppna eller inspektera den sparade filen innan den lämnas till ett annat system eller kunden

Felmoder att öva

  • En lyckad SaveAs bevisar inte att affärskontraktet fortfarande är korrekt
  • Typsnitt, behörigheter och regionala inställningar kan skilja mellan server och utvecklingsdator
  • Loggar får inte exponera lösenord, kunddata eller interna länkar

Detaljerat Delphi-exempel

Följande Delphi-exempel visar en praktisk servicegräns för ämnet och håller policy, loggning och validering testbart separerade

procedure RoundTripOdsWorkbook(const InputOds, OutputOds: string);
var
  Wb: TXLSXWorkbook;
  BeforeState: TWorkbookInventory;
  AfterState: TWorkbookInventory;
begin
  RequireFileExists(InputOds);
  Wb := TXLSXWorkbook.Create;
  try
    Wb.Open(InputOds);
    BeforeState := CaptureWorkbookInventory(Wb);
    NormalizeFeaturesForOdsOutput(Wb);
    WriteCompatibilitySheet(Wb, BeforeState, 'ods-round-trip');

    if Wb.SaveAs(OutputOds) <> 1 then
      RaiseWorkbookSaveError(OutputOds);

    AfterState := InspectSavedWorkbook(OutputOds);
    CompareRoundTripInventory(BeforeState, AfterState, [
      'sheet-count',
      'used-ranges',
      'formula-cells',
      'visible-styles'
    ]);
  finally
    Wb.Free;
  end;
end;

Produktionschecklista

  • 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