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 developers exporting workbook data to integration feeds, web previews, reports, and legacy document flows. Traktuje CSV, TSV, HTML, and RTF export jako produkcyjną inżynierię dokumentów, a nie pojedyncze wywołanie komponentu.
Praktyczne ryzyko polega na tym, że export formats lose workbook semantics in different ways, so data, encoding, formulas, styles, and selected ranges need explicit product policy. Dlatego przepływ wymaga spisanego kontraktu, obserwowalnej diagnostyki i realistycznych plików regresyjnych.
Decyzje architektoniczne
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
Przebieg implementacji
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
Dowody walidacji
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.
Uwagi wdrożeniowe dla produkcji
Traktuj HotXLS Component: CSV, TSV, HTML, and RTF export 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 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;
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