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 generating visual Excel reports, dashboards, or template-based workbooks in Delphi. Tratta charts, images, and drawing objects come ingegneria documentale di produzione, non come una semplice chiamata al componente.
Il rischio pratico è che visual workbook elements fail when anchors, sheet changes, chart ranges, image DPI, and drawing identifiers are treated as decorative afterthoughts. Per questo il flusso richiede un contratto scritto, diagnostica osservabile e file di regressione realistici.
Decisioni architetturali
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
Percorso di implementazione
Bind visuals to stable ranges and anchors. The order below keeps the workflow reviewable for Delphi and C++Builder teams.
- prepare named ranges or stable addresses before creating chart objects
- normalize image dimensions and compression before insertion
- place drawings with the intended cell anchor and movement behavior
- recalculate or refresh chart ranges after data changes
- open the workbook in the target Excel version and inspect layout at print scale
Evidenze di validazione
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.
Note di implementazione per la produzione
Tratta HotXLS: charts, images, and drawing objects in Delphi 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 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;
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