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 exporting workbook data to integration feeds, web previews, reports, and legacy document flows. Tratta CSV, TSV, HTML, and RTF export come ingegneria documentale di produzione, non come una semplice chiamata al componente.
Il rischio pratico è che export formats lose workbook semantics in different ways, so data, encoding, formulas, styles, and selected ranges need explicit product policy. Per questo il flusso richiede un contratto scritto, diagnostica osservabile e file di regressione realistici.
Decisioni architetturali
Define the target format contract. selected sheets, ranges, headers, hidden rows, and filtered data policy / encoding, delimiter, quote, newline, decimal, and date formatting rules
- selected sheets, ranges, headers, hidden rows, and filtered data policy
- encoding, delimiter, quote, newline, decimal, and date formatting rules
- formula output as cached values, formulas, or blocked content
- style preservation expectations for HTML and RTF compared with workbook layout
Percorso di implementazione
Choose data fidelity before visual fidelity. The order below keeps the workflow reviewable for Delphi and C++Builder teams.
- select the export profile from the target system rather than from file extension alone
- normalize data types and locale-sensitive formats before writing delimited output
- escape delimiters, quotes, line breaks, and HTML-sensitive characters deliberately
- record which workbook features were dropped or simplified
- validate exported files with the downstream importer or browser target
Evidenze di validazione
Export evidence for downstream consumers. Keep these fields with the output or support record.
- format, encoding, delimiter, selected range, row count, and column count
- formula handling, hidden-row policy, filter policy, and style-loss warnings
- downstream import result or web-preview verification
- sample records showing quote, newline, Unicode, date, and number behavior
Every export format is a tradeoff
CSV and TSV emphasize delimited data, HTML emphasizes presentation and web preview, and RTF emphasizes styled document interchange. The application should decide which workbook features are preserved, flattened, or rejected.
Note di implementazione per la produzione
Tratta HotXLS Component: CSV, TSV, HTML, and RTF export 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 ExportWorkbookViews(const WorkbookFile, OutputFolder: string; const Profiles: TArray<TExportProfile>);
var
Wb: TXLSXWorkbook;
Profile: TExportProfile;
ExportPath: string;
begin
RequireFolder(OutputFolder);
Wb := TXLSXWorkbook.Create;
try
Wb.Open(WorkbookFile);
for Profile in Profiles do
begin
RequireExportRange(Wb, Profile.SheetName, Profile.RangeAddress);
ExportPath := BuildExportPath(OutputFolder, Profile);
case Profile.Format of
efCsv: ExportRangeAsCsv(Wb, Profile, ExportPath);
efTsv: ExportRangeAsTsv(Wb, Profile, ExportPath);
efHtml: ExportRangeAsHtml(Wb, Profile, ExportPath);
else
RaiseUnsupportedExportFormat(Profile.Format);
end;
ValidateExportRecordCount(Profile, ExportPath);
AppendExportManifest(OutputFolder, Profile, ExportPath);
end;
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