技術記事

HotXLS Component: Delphi での protection, page setup, and printing

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

この記事は developers delivering workbooks that users review, print, and partly edit under controlled rules 向けです。protection, page setup, and printing を単なるコンポーネント呼び出しではなく、本番向けのドキュメントエンジニアリングとして扱います。

実務上のリスクは sheet protection and print settings are easy to apply but hard to support when editable ranges, headers, page breaks, scaling, and printer assumptions are undocumented です。そのため、明確な契約、観測可能な診断、実際の顧客ファイルに近い回帰サンプルが必要です。

アーキテクチャ上の判断

Define edit and print intent together. locked cells, editable ranges, sheet protection password, and allowed user actions / print area, repeat rows and columns, headers, footers, margins, scaling, and orientation

  • locked cells, editable ranges, sheet protection password, and allowed user actions
  • print area, repeat rows and columns, headers, footers, margins, scaling, and orientation
  • manual versus automatic page breaks and how generated rows affect them
  • whether protection is advisory workflow control or part of a stronger governance model

実装フロー

Apply protection after layout is final. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  1. finish data generation and layout expansion before enabling protection
  2. mark editable ranges and validate that formulas and headers remain locked
  3. apply page setup, print titles, margins, scaling, and page breaks
  4. open print preview in the target workbook application
  5. record the protection and print profile used for support

検証エビデンス

Workbook evidence for print and protection disputes. Keep these fields with the output or support record.

  • protected sheets, editable ranges, allowed actions, and password policy identifier
  • print area, repeat titles, margins, orientation, scaling, and page count
  • manual page breaks and dynamic row expansion results
  • preview or printed-output verification for representative data volumes

Protection is workflow guidance, not security alone

Workbook protection helps guide user edits, while page setup controls physical output. They interact: locked cells, print areas, headers, scaling, and page breaks should all match the business document contract.

本番実装の要点

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

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

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

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

詳しい Delphi サンプル

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

procedure BuildProtectedPrintWorkbook(const OutputFile: string; const Rows: TArray<TPrintRow>);
var
  Wb: TXLSWorkbook;
  Sh: IXLSWorksheet;
  RowIndex: Integer;
  Row: TPrintRow;
begin
  Wb := TXLSWorkbook.Create;
  try
    Sh := Wb.Sheets[1];
    Sh.Name := 'Print Pack';
    WriteHeaderRow(Sh, ['Item', 'Owner', 'Due', 'Amount']);

    RowIndex := 2;
    for Row in Rows do
    begin
      Sh.Range['A' + IntToStr(RowIndex)].Value := Row.ItemName;
      Sh.Range['B' + IntToStr(RowIndex)].Value := Row.Owner;
      Sh.Range['C' + IntToStr(RowIndex)].Value := Row.DueDate;
      Sh.Range['D' + IntToStr(RowIndex)].Value := Row.Amount;
      Inc(RowIndex);
    end;

    Sh.Range['A1:D1'].ApplyBuiltinStyle(xbsTitle);
    ConfigurePrintArea(Sh, 'A1:D' + IntToStr(RowIndex - 1));
    ConfigurePageSetup(Sh, poLandscape, psFitToWidth);
    LockFormulaCellsOnly(Sh);
    ProtectWorksheetForReview(Sh, 'review-password');

    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