Twórz, edytuj, sprawdzaj, obliczaj i eksportuj skoroszyty Excel bezpośrednio z kodu Delphi lub C++Builder. HotXLS to natywna biblioteka Object Pascal z kodem źródłowym dla przepływów XLS i XLSX, przeznaczona do narzędzi desktopowych, zadań batch, systemów raportowych i generowania dokumentów po stronie serwera bez automatyzacji Microsoft Excel.
Ten artykuł jest przeznaczony dla teams producing customer-facing workbooks from maintained Excel templates rather than assembling every cell in code. Traktuje template-based report generation jako produkcyjną inżynierię dokumentów, a nie pojedyncze wywołanie komponentu.
Praktyczne ryzyko polega na tym, że template-driven output becomes fragile when placeholder ownership, dynamic rows, styles, formulas, and localization are not versioned. Dlatego przepływ wymaga spisanego kontraktu, obserwowalnej diagnostyki i realistycznych plików regresyjnych.
Decyzje architektoniczne
Make templates part of the application interface. placeholder syntax, required values, repeated regions, and named-range ownership / style preservation, formula refresh, merged-cell behavior, and row insertion rules
- placeholder syntax, required values, repeated regions, and named-range ownership
- style preservation, formula refresh, merged-cell behavior, and row insertion rules
- localization of labels, number formats, dates, and sheet names
- template versioning, approval, rollback, and compatibility with old data profiles
Przebieg implementacji
Bind placeholders to typed data contracts. The order below keeps the workflow reviewable for Delphi and C++Builder teams.
- validate template version and required placeholders before loading data
- bind typed data to named ranges or placeholder regions
- expand repeating sections while preserving formulas, styles, merges, and page breaks
- calculate and validate key cells after data insertion
- store template version and placeholder results with the generated workbook
Dowody walidacji
Template evidence that speeds up support. Keep these fields with the output or support record.
- template version, data profile, placeholder list, and missing-placeholder warnings
- expanded region sizes, inserted rows, formula refresh status, and style preservation
- localized label set and number-format profile
- regression workbook comparison against approved samples
A template is executable design
A workbook template carries layout, formatting, formulas, and business assumptions. The code should treat placeholders, named ranges, and repeating regions as a documented contract rather than free-form cell addresses.
Uwagi wdrożeniowe dla produkcji
Traktuj HotXLS Component: template-based report generation in Delphi jako jawny kontrakt usługi wokół wywołań HotXLS, oddzielając walidację wejścia, zapis skoroszytu, kontrolę wyniku i dowody dla wsparcia
- Ustal źródło danych, zakresy komórek i format wyjściowy przed utworzeniem skoroszytu
- Zapisuj liczbę wierszy, arkusze, ostrzeżenia i ścieżkę wyjściową w możliwym do sprawdzenia logu
- Szczegóły aplikacji zamykaj w testowalnych helperach zamiast w zdarzeniach UI
- Otwórz lub sprawdź zapisany plik przed przekazaniem go do innego systemu lub klienta
Tryby awarii do przećwiczenia
- Udany SaveAs nie dowodzi, że kontrakt biznesowy nadal jest poprawny
- Czcionki, uprawnienia i ustawienia regionalne mogą różnić się między serwerem a maszyną deweloperską
- Logi nie mogą ujawniać haseł, danych klientów ani linków wewnętrznych
Szczegółowy przykład Delphi
Poniższy przykład Delphi pokazuje praktyczną granicę usługi dla tego tematu, z polityką, logowaniem i walidacją w warstwie możliwej do testowania
procedure GenerateReportFromTemplate(const TemplateFile, OutputFile: string; const Context: TReportContext);
var
Wb: TXLSXWorkbook;
begin
RequireFileExists(TemplateFile);
Wb := TXLSXWorkbook.Create;
try
Wb.Open(TemplateFile);
EnsureTemplateVersion(Wb, Context.TemplateVersion);
SetNamedValue(Wb, 'ReportTitle', Context.Title);
SetNamedValue(Wb, 'ReportPeriod', Context.PeriodText);
FillNamedTable(Wb, 'RevenueRows', Context.RevenueRows);
FillNamedTable(Wb, 'ExpenseRows', Context.ExpenseRows);
Wb.Calculate;
AssertNoUnresolvedTemplateMarkers(Wb);
AssertRequiredSheetsVisible(Wb, ['Cover', 'Summary', 'Detail']);
WriteGenerationAudit(Wb, Context);
if Wb.SaveAs(OutputFile) <> 1 then
RaiseWorkbookSaveError(OutputFile);
finally
Wb.Free;
end;
end;
Lista produkcyjna
- 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