Cree, edite, inspeccione, calcule y exporte libros de Excel directamente desde código Delphi o C++Builder. HotXLS es una biblioteca nativa Object Pascal para XLS y XLSX, disenada para herramientas de escritorio, trabajos por lotes, informes y generacion de documentos sin automatización de Microsoft Excel.
Este artículo está dirigido a developers generating workbooks whose calculated results are part of the product output. Presenta formula calculation and custom functions como una práctica de ingeniería documental para producción, no como una llamada aislada al componente.
El riesgo principal es que formula results can appear correct in simple cases while dependency order, custom functions, locale parsing, volatile functions, or error values differ in production. Por eso el flujo necesita contrato escrito, diagnósticos observables y archivos de regresión reales.
Decisiones de arquitectura
Treat calculation as a deterministic service. calculation mode, dependency refresh, and whether cached values are trusted / custom function names, argument types, null handling, and versioning
- calculation mode, dependency refresh, and whether cached values are trusted
- custom function names, argument types, null handling, and versioning
- locale handling for decimal separators, date literals, and function names
- error-value policy for invalid references, division by zero, and unsupported formulas
Flujo de implementación
Register custom functions before loading dependent formulas. The order below keeps the workflow reviewable for Delphi and C++Builder teams.
- register custom functions and workbook names before calculation
- load or generate formulas with explicit dependency expectations
- calculate targeted ranges or full workbook output according to the profile
- compare critical results with independent fixtures or approved Excel output
- write calculation diagnostics into the support bundle when results are disputed
Evidencia de validación
Calculation evidence for finance and support. Keep these fields with the output or support record.
- formula count, dependency graph summary, custom function calls, and recalculation time
- critical cell addresses, formula text, cached value, calculated value, and error state
- custom function version, arguments, returned value, and exception mapping
- locale profile and unsupported-formula warnings
Custom functions need versioned behavior
A formula engine workflow should make dependencies, custom function registration, recalculation mode, cached results, and error handling visible. That is especially important when generated workbooks are consumed without Excel automation.
Notas de implementación para producción
Trata HotXLS: formula calculation and custom functions in Delphi como un contrato de servicio claro alrededor de las llamadas a HotXLS, separando validación de entrada, escritura del libro, comprobación de salida y evidencias de soporte
- Define origen de datos, rangos de celdas y formato de salida antes de crear el libro
- Registra filas, hojas, advertencias y ruta de salida en una evidencia revisable
- Encapsula los detalles propios de la aplicación en helpers comprobables, no en eventos de interfaz
- Vuelve a abrir o inspecciona el archivo guardado antes de entregarlo a otro sistema o al cliente
Fallos que conviene ensayar
- Que SaveAs devuelva éxito no demuestra que el contrato de negocio siga siendo correcto
- Fuentes, permisos y configuración regional pueden cambiar entre servidor y equipo de desarrollo
- Los logs no deben exponer contraseñas, datos de clientes ni enlaces internos
Ejemplo Delphi detallado
El siguiente ejemplo Delphi muestra una frontera de servicio práctica para este tema y mantiene políticas, registro y validación en una capa comprobable
procedure RecalculateInvoiceWorkbook(const TemplateFile, OutputFile: string; const Orders: TArray<TOrderRow>);
var
Wb: TXLSXWorkbook;
Sh: IXLSWorksheet;
RowIndex: Integer;
Order: TOrderRow;
begin
Wb := TXLSXWorkbook.Create;
try
Wb.Open(TemplateFile);
RegisterInvoiceFunctions(Wb);
Sh := Wb.Sheets[0];
EnsureTemplateVersion(Wb, 'invoice-formulas-v3');
RowIndex := 2;
for Order in Orders do
begin
Sh.Range['A' + IntToStr(RowIndex)].Value := Order.Sku;
Sh.Range['B' + IntToStr(RowIndex)].Value := Order.Quantity;
Sh.Range['C' + IntToStr(RowIndex)].Value := Order.UnitPrice;
Sh.Range['D' + IntToStr(RowIndex)].Value := '=B' + IntToStr(RowIndex) + '*C' + IntToStr(RowIndex);
Sh.Range['E' + IntToStr(RowIndex)].Value := '=InvoiceTax(D' + IntToStr(RowIndex) + ')';
Inc(RowIndex);
end;
Wb.Calculate;
AssertFormulaRangeHasValues(Sh, 'D2:E' + IntToStr(RowIndex - 1));
WriteCalculationAudit(Wb, 'invoice-formulas', RowIndex - 2);
if Wb.SaveAs(OutputFile) <> 1 then
RaiseWorkbookSaveError(OutputFile);
finally
Wb.Free;
end;
end;
Lista de salida a producción
- 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