技術記事

HotXLS Component: Delphi での charts, images, and drawing objects

Delphi または C++Builder コードから直接 Excel ワークブックを作成、編集、検査、計算、エクスポートできます。HotXLS はソース付き Object Pascal スプレッドシートライブラリで、XLS/XLSX ワークフロー、デスクトップツール、バッチジョブ、レポート、Excel 自動化なしのサーバー側生成に適しています。

この記事は developers generating visual Excel reports, dashboards, or template-based workbooks in Delphi 向けです。charts, images, and drawing objects を単なるコンポーネント呼び出しではなく、本番向けのドキュメントエンジニアリングとして扱います。

実務上のリスクは visual workbook elements fail when anchors, sheet changes, chart ranges, image DPI, and drawing identifiers are treated as decorative afterthoughts です。そのため、明確な契約、観測可能な診断、実際の顧客ファイルに近い回帰サンプルが必要です。

アーキテクチャ上の判断

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

実装フロー

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

検証エビデンス

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.

本番実装の要点

HotXLS Component: Delphi での charts, images, and drawing objects は HotXLS 呼び出しの前後に置く明確なサービス契約として扱い、入力検証、ブック作成、出力確認、サポート証跡を分離します

  • ブックを作成する前にデータソース、セル範囲、出力形式を確定する
  • 行数、シート数、警告、出力先をレビュー可能な証跡として記録する
  • アプリ固有の処理は UI イベントではなくテスト可能な helper に閉じ込める
  • 保存済みファイルを別システムや顧客へ渡す前に再オープンまたは検査する

事前に試験すべき失敗パターン

  • SaveAs の成功だけでは業務契約が正しいとは言えません
  • サーバーと開発機ではフォント、権限、地域設定が異なることがあります
  • ログにパスワード、顧客データ、内部リンクを残してはいけません

詳しい Delphi サンプル

次の Delphi 例は、このテーマをサービス境界として実装する形を示し、ポリシー、ログ、検証をテスト可能な層に分けます

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;

本番チェックリスト

  • 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