Artículo técnico

HotXLS: conditional formatting, rich text, and styles

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 teams producing formatted workbook output that must remain editable and visually consistent. Presenta conditional formatting, rich text, and styles como una práctica de ingeniería documental para producción, no como una llamada aislada al componente.

El riesgo principal es que style-heavy workbooks become slow, bloated, or visually inconsistent when every cell creates a new style or when conditional rules overlap without priority control. Por eso el flujo necesita contrato escrito, diagnósticos observables y archivos de regresión reales.

Decisiones de arquitectura

Manage styles as reusable assets. style catalog, theme colors, indexed colors, fonts, borders, and number formats / conditional-rule priority, stop-if-true behavior, and target ranges

  • style catalog, theme colors, indexed colors, fonts, borders, and number formats
  • conditional-rule priority, stop-if-true behavior, and target ranges
  • rich text runs, hyperlink styling, and localization of inline labels
  • style reuse policy for generated rows and template-derived sections

Flujo de implementación

Apply formatting through named profiles. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  1. define style profiles before writing large ranges
  2. reuse existing workbook styles when they match the intended appearance
  3. apply conditional rules in explicit priority order
  4. write rich text runs only where the mixed formatting carries meaning
  5. inspect style count and workbook size as part of regression testing

Evidencia de validación

Formatting evidence for regression review. Keep these fields with the output or support record.

  • style count, reused style identifiers, and newly created style profiles
  • conditional rule type, priority, target range, and formula or threshold
  • rich text run count, font changes, and hyperlink interactions
  • visual comparison against approved template output

Workbook formatting has a cost model

Conditional formatting, rich text runs, and cell styles are workbook resources. Reusing styles and explaining rule priority improves performance, file size, and long-term template maintenance.

Notas de implementación para producción

Trata HotXLS: conditional formatting, rich text, and styles 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 BuildKpiWorkbook(const OutputFile: string; const Rows: TArray<TKpiRow>);
var
  Wb: TXLSXWorkbook;
  Sh: IXLSWorksheet;
  RowIndex: Integer;
  Row: TKpiRow;
begin
  Wb := TXLSXWorkbook.Create;
  try
    Sh := Wb.Sheets[0];
    Sh.Name := 'KPI Review';
    WriteHeaderRow(Sh, ['Team', 'Owner', 'Target', 'Actual', 'Status']);

    RowIndex := 2;
    for Row in Rows do
    begin
      Sh.Range['A' + IntToStr(RowIndex)].Value := Row.Team;
      Sh.Range['B' + IntToStr(RowIndex)].Value := Row.Owner;
      Sh.Range['C' + IntToStr(RowIndex)].Value := Row.Target;
      Sh.Range['D' + IntToStr(RowIndex)].Value := Row.Actual;
      Sh.Range['E' + IntToStr(RowIndex)].Value := Row.StatusText;
      Inc(RowIndex);
    end;

    Sh.Range['A1:E1'].ApplyBuiltinStyle(xbsTitle);
    ApplyCurrencyFormat(Sh, 'C2:D' + IntToStr(RowIndex - 1));
    AddTrafficLightRules(Sh, 'E2:E' + IntToStr(RowIndex - 1));
    AddRichTextStatusNotes(Sh, Rows, 2);
    ValidateStyleBudget(Wb, 80);

    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

Product documentation

HotXLS Component