Delphi または C++Builder コードから直接 Excel ワークブックを作成、編集、検査、計算、エクスポートできます。HotXLS はソース付き Object Pascal スプレッドシートライブラリで、XLS/XLSX ワークフロー、デスクトップツール、バッチジョブ、レポート、Excel 自動化なしのサーバー側生成に適しています。
この記事は teams moving datasets from Delphi applications into customer-ready workbook reports 向けです。database export to spreadsheet reports を単なるコンポーネント呼び出しではなく、本番向けのドキュメントエンジニアリングとして扱います。
実務上のリスクは a dataset dump is not a report when type conversion, null handling, totals, grouping, sorting, and workbook styling are not part of the export contract です。そのため、明確な契約、観測可能な診断、実際の顧客ファイルに近い回帰サンプルが必要です。
アーキテクチャ上の判断
Treat the dataset schema as a workbook contract. field-to-column mapping, captions, order, grouping, and sort rules / null, date, time zone, currency, decimal, and Boolean formatting
- field-to-column mapping, captions, order, grouping, and sort rules
- null, date, time zone, currency, decimal, and Boolean formatting
- formula totals, subtotals, filters, frozen panes, and table-like navigation
- streaming, pagination, and memory policy for large result sets
実装フロー
Map database fields to worksheet semantics. The order below keeps the workflow reviewable for Delphi and C++Builder teams.
- derive an export profile from the report requirement and dataset schema
- validate field types and required columns before creating the workbook
- write headers, formats, and formulas before streaming large row groups
- apply filters, freeze panes, totals, and page setup after the data range is known
- compare row counts and key aggregates with the source query
検証エビデンス
Export diagnostics for support and finance teams. Keep these fields with the output or support record.
- query identifier, field mapping, row count, column count, and export profile
- null and data-type conversions, locale profile, and formula summary
- source aggregate totals compared with workbook totals
- warnings for truncated text, unsupported types, or memory-limit fallback
Types matter more than cell values
Database export needs explicit mapping from field types to worksheet cells, number formats, formulas, totals, and visible labels. Without that mapping, users receive a workbook that looks correct but behaves poorly in analysis.
本番実装の要点
HotXLS Component: Delphi での database export to spreadsheet reports は HotXLS 呼び出しの前後に置く明確なサービス契約として扱い、入力検証、ブック作成、出力確認、サポート証跡を分離します
- ブックを作成する前にデータソース、セル範囲、出力形式を確定する
- 行数、シート数、警告、出力先をレビュー可能な証跡として記録する
- アプリ固有の処理は UI イベントではなくテスト可能な helper に閉じ込める
- 保存済みファイルを別システムや顧客へ渡す前に再オープンまたは検査する
事前に試験すべき失敗パターン
- SaveAs の成功だけでは業務契約が正しいとは言えません
- サーバーと開発機ではフォント、権限、地域設定が異なることがあります
- ログにパスワード、顧客データ、内部リンクを残してはいけません
詳しい Delphi サンプル
次の Delphi 例は、このテーマをサービス境界として実装する形を示し、ポリシー、ログ、検証をテスト可能な層に分けます
procedure ExportCustomerReport(DataSet: TDataSet; const OutputFile: string);
var
Wb: TXLSXWorkbook;
Sh: IXLSWorksheet;
RowIndex: Integer;
begin
RequireOpenDataSet(DataSet);
Wb := TXLSXWorkbook.Create;
try
Sh := Wb.Sheets[0];
Sh.Name := 'Customers';
WriteHeaderRow(Sh, ['CustomerId', 'Name', 'Region', 'Balance', 'LastOrder']);
RowIndex := 2;
DataSet.First;
while not DataSet.Eof do
begin
Sh.Range['A' + IntToStr(RowIndex)].Value := DataSet.FieldByName('CustomerId').AsString;
Sh.Range['B' + IntToStr(RowIndex)].Value := DataSet.FieldByName('Name').AsString;
Sh.Range['C' + IntToStr(RowIndex)].Value := DataSet.FieldByName('Region').AsString;
Sh.Range['D' + IntToStr(RowIndex)].Value := DataSet.FieldByName('Balance').AsCurrency;
Sh.Range['E' + IntToStr(RowIndex)].Value := DataSet.FieldByName('LastOrder').AsDateTime;
Inc(RowIndex);
DataSet.Next;
end;
Sh.Range['A1:E1'].ApplyBuiltinStyle(xbsTitle);
ApplyDateAndCurrencyFormats(Sh, RowIndex - 1);
AddAutoFilterToHeader(Sh, 'A1:E' + IntToStr(RowIndex - 1));
WriteExportManifest(Wb, DataSet, 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