Artykuł techniczny

HotXLS: charts, images, and drawing objects in Delphi

Twórz, edytuj, sprawdzaj, obliczaj i eksportuj skoroszyty Excel bezpośrednio z kodu Delphi lub C++Builder. HotXLS to natywna biblioteka Object Pascal z kodem źródłowym dla przepływów XLS i XLSX, przeznaczona do narzędzi desktopowych, zadań batch, systemów raportowych i generowania dokumentów po stronie serwera bez automatyzacji Microsoft Excel.

Ten artykuł jest przeznaczony dla developers generating visual Excel reports, dashboards, or template-based workbooks in Delphi. Traktuje charts, images, and drawing objects jako produkcyjną inżynierię dokumentów, a nie pojedyncze wywołanie komponentu.

Praktyczne ryzyko polega na tym, że visual workbook elements fail when anchors, sheet changes, chart ranges, image DPI, and drawing identifiers are treated as decorative afterthoughts. Dlatego przepływ wymaga spisanego kontraktu, obserwowalnej diagnostyki i realistycznych plików regresyjnych.

Decyzje architektoniczne

Treat drawings as workbook data. chart data range ownership and whether ranges expand with inserted rows / image source, DPI, compression, transparency, and alternate text policy

  • chart data range ownership and whether ranges expand with inserted rows
  • image source, DPI, compression, transparency, and alternate text policy
  • object anchoring behavior when cells resize, hide, or move
  • whether existing drawings are preserved, replaced, or regenerated from templates

Przebieg implementacji

Bind visuals to stable ranges and anchors. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  1. prepare named ranges or stable addresses before creating chart objects
  2. normalize image dimensions and compression before insertion
  3. place drawings with the intended cell anchor and movement behavior
  4. recalculate or refresh chart ranges after data changes
  5. open the workbook in the target Excel version and inspect layout at print scale

Dowody walidacji

Visual-output evidence for workbook support. Keep these fields with the output or support record.

  • chart type, source range, sheet name, and series count
  • image dimensions, DPI, compression mode, anchor cell, and object identifier
  • drawing preservation or regeneration decision for each template object
  • viewer compatibility notes for Excel, LibreOffice, or downstream conversion

A chart depends on workbook structure

Charts, pictures, and shapes are connected to sheets, cell anchors, relationships, and sometimes formulas. A reliable workflow keeps those relationships stable when rows, columns, templates, or sheet order change.

Uwagi wdrożeniowe dla produkcji

Traktuj HotXLS: charts, images, and drawing objects in Delphi jako jawny kontrakt usługi wokół wywołań HotXLS, oddzielając walidację wejścia, zapis skoroszytu, kontrolę wyniku i dowody dla wsparcia

  • Ustal źródło danych, zakresy komórek i format wyjściowy przed utworzeniem skoroszytu
  • Zapisuj liczbę wierszy, arkusze, ostrzeżenia i ścieżkę wyjściową w możliwym do sprawdzenia logu
  • Szczegóły aplikacji zamykaj w testowalnych helperach zamiast w zdarzeniach UI
  • Otwórz lub sprawdź zapisany plik przed przekazaniem go do innego systemu lub klienta

Tryby awarii do przećwiczenia

  • Udany SaveAs nie dowodzi, że kontrakt biznesowy nadal jest poprawny
  • Czcionki, uprawnienia i ustawienia regionalne mogą różnić się między serwerem a maszyną deweloperską
  • Logi nie mogą ujawniać haseł, danych klientów ani linków wewnętrznych

Szczegółowy przykład Delphi

Poniższy przykład Delphi pokazuje praktyczną granicę usługi dla tego tematu, z polityką, logowaniem i walidacją w warstwie możliwej do testowania

procedure BuildSalesDashboardWorkbook(const OutputFile, LogoFile: string; const Rows: TArray<TSalesRow>);
var
  Wb: TXLSXWorkbook;
  Sh: IXLSWorksheet;
  RowIndex: Integer;
  Row: TSalesRow;
begin
  Wb := TXLSXWorkbook.Create;
  try
    Sh := Wb.Sheets[0];
    Sh.Name := 'Dashboard';
    Sh.Range['A1'].Value := 'Quarter';
    Sh.Range['B1'].Value := 'Revenue';
    Sh.Range['C1'].Value := 'Margin';
    Sh.Range['D1'].Value := 'Pipeline';

    RowIndex := 2;
    for Row in Rows do
    begin
      Sh.Range['A' + IntToStr(RowIndex)].Value := Row.Quarter;
      Sh.Range['B' + IntToStr(RowIndex)].Value := Row.Revenue;
      Sh.Range['C' + IntToStr(RowIndex)].Value := Row.Margin;
      Sh.Range['D' + IntToStr(RowIndex)].Value := Row.Pipeline;
      Inc(RowIndex);
    end;

    Sh.Range['A1:D1'].ApplyBuiltinStyle(xbsTitle);
    Sh.Range['A2:D' + IntToStr(RowIndex - 1)].ApplyBuiltinStyle(xbsGood);
    AddColumnChart(Sh, 'A1:D' + IntToStr(RowIndex - 1), 'F3:M18');
    AddImageIfPresent(Sh, LogoFile, 'F1');
    WriteWorkbookAudit(Wb, 'dashboard', RowIndex - 2);

    if Wb.SaveAs(OutputFile) <> 1 then
      RaiseWorkbookSaveError(OutputFile);
  finally
    Wb.Free;
  end;
end;

Lista produkcyjna

  • 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