Crea, modifica, ispeziona, calcola ed esporta cartelle di lavoro Excel direttamente da Delphi o C++Builder. HotXLS e una libreria nativa Object Pascal per XLS e XLSX, progettata per strumenti desktop, batch, report e generazione documenti senza automazione Microsoft Excel.
Questo articolo è rivolto a developers maintaining polished workbook templates for invoices, statements, labels, or management reports. Tratta merged cells and layout-driven report templates come ingegneria documentale di produzione, non come una semplice chiamata al componente.
Il rischio pratico è che merged-cell layouts look convenient but can break sorting, filtering, row insertion, accessibility, and downstream export if they are not constrained. Per questo il flusso richiede un contratto scritto, diagnostica osservabile e file di regressione realistici.
Decisioni architetturali
Use merged cells only for deliberate layout regions. which template regions may use merged cells and which data regions may not / row-height, wrap, print-area, and page-break behavior for generated content
- which template regions may use merged cells and which data regions may not
- row-height, wrap, print-area, and page-break behavior for generated content
- placeholder replacement rules inside merged ranges
- fallback behavior for export formats that do not preserve merge semantics well
Percorso di implementazione
Separate layout areas from data areas. The order below keeps the workflow reviewable for Delphi and C++Builder teams.
- mark template regions as layout, data, summary, or print-only before generation
- validate that generated data does not cross merge boundaries unexpectedly
- replace placeholders while preserving row heights, borders, and alignment
- apply page breaks and print areas after dynamic sections expand
- test sort, filter, copy, print, and export workflows on the final workbook
Evidenze di validazione
Template evidence that explains layout decisions. Keep these fields with the output or support record.
- merged ranges, owning template region, placeholder names, and expansion result
- row-height and wrap decisions for generated text
- page-break, print-area, and scaling settings
- warnings when merged layout conflicts with sorting, filtering, or export
Layout templates need structural rules
Merged cells are useful for titles, grouped headers, and fixed report areas, but they should not be used casually inside data ranges that users sort, filter, copy, or import later.
Note di implementazione per la produzione
Tratta HotXLS: merged cells and layout-driven report templates come un contratto di servizio esplicito attorno alle chiamate HotXLS, separando validazione dell'input, scrittura della cartella, controllo dell'output ed evidenze di supporto
- Definire origine dati, intervalli di celle e formato di output prima di creare la cartella
- Registrare righe, fogli, avvisi e percorso di output in una prova verificabile
- Incapsulare i dettagli applicativi in helper testabili invece che in eventi UI
- Riaprire o ispezionare il file salvato prima di consegnarlo a un altro sistema o al cliente
Casi di errore da provare
- Un SaveAs riuscito non prova che il contratto di business sia corretto
- Font, permessi e impostazioni locali possono variare tra server e macchina di sviluppo
- I log non devono esporre password, dati cliente o link interni
Esempio Delphi dettagliato
L'esempio Delphi seguente mostra un confine di servizio pratico per questo tema, mantenendo policy, logging e validazione in un livello testabile
procedure BuildMergedLayoutReport(const OutputFile: string; const Sections: TArray<TReportSection>);
var
Wb: TXLSWorkbook;
Sh: IXLSWorksheet;
RowIndex: Integer;
Section: TReportSection;
begin
Wb := TXLSWorkbook.Create;
try
Sh := Wb.Sheets[1];
Sh.Name := 'Board Pack';
Sh.Range['A1:F1'].Merge;
Sh.Range['A1'].Value := 'Executive Board Pack';
Sh.Range['A1:F1'].ApplyBuiltinStyle(xbsTitle);
RowIndex := 3;
for Section in Sections do
begin
Sh.Range['A' + IntToStr(RowIndex) + ':F' + IntToStr(RowIndex)].Merge;
Sh.Range['A' + IntToStr(RowIndex)].Value := Section.Title;
Inc(RowIndex);
WriteSectionRows(Sh, RowIndex, Section.Rows);
Inc(RowIndex, Length(Section.Rows) + 1);
end;
AssertMergedHeadersDoNotHideData(Sh);
ConfigurePrintArea(Sh, 'A1:F' + IntToStr(RowIndex - 1));
if Wb.SaveAs(OutputFile) <> 1 then
RaiseWorkbookSaveError(OutputFile);
finally
Wb.Free;
end;
end;
Checklist di produzione
- 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