/** * Worksheet conditional formatting (`CT_ConditionalFormatting` / `CT_CfRule`). * * Citations: * - ECMA-376-1 §18.3.1.18 `conditionalFormatting` / §18.3.1.10 `cfRule` * - transitional sml.xsd `CT_ConditionalFormatting` / `CT_CfRule` / * `ST_CfType` / `ST_ConditionalFormattingOperator` / `ST_TimePeriod` / `ST_Sqref` * - docs/specs/conditional-formatting.md * - docs/ooxml-mapping/conditional-formatting.md * * Formulas are opaque text (never evaluated). Empty collection omits all CF * parents. Rules sharing identical formatted sqref + pivot group into one parent * on serialize. Overlapping sqref is allowed; add always appends. */ import { CellRange } from '../address/cell-address'; import { Color, DifferentialFormatInput, DifferentialFormatView } from '../styles/styles-xml'; import { WorkbookStyles } from '../styles/workbook-styles'; /** * Specifies the kind of condition a formatting rule tests, such as * comparing values, ranking them, or matching text. */ export declare type ConditionalFormatType = 'expression' | 'cellIs' | 'colorScale' | 'dataBar' | 'iconSet' | 'top10' | 'uniqueValues' | 'duplicateValues' | 'containsText' | 'notContainsText' | 'beginsWith' | 'endsWith' | 'containsBlanks' | 'notContainsBlanks' | 'containsErrors' | 'notContainsErrors' | 'timePeriod' | 'aboveAverage'; /** * Specifies the comparison a rule applies to cell values, such as * greater-than or between. */ export declare type ConditionalFormatOperator = 'lessThan' | 'lessThanOrEqual' | 'equal' | 'notEqual' | 'greaterThanOrEqual' | 'greaterThan' | 'between' | 'notBetween' | 'containsText' | 'notContains' | 'beginsWith' | 'endsWith'; /** Specifies the time period a rule matches, such as today or last month. */ export declare type ConditionalFormatTimePeriod = 'today' | 'yesterday' | 'tomorrow' | 'last7Days' | 'thisMonth' | 'lastMonth' | 'nextMonth' | 'thisWeek' | 'lastWeek' | 'nextWeek'; /** * Specifies how a threshold's value is chosen for data bar, color scale, * and icon set rules — for example a fixed number, a percentage, or the * lowest or highest value in the range. */ export declare type CfThresholdType = 'lowestValue' | 'highestValue' | 'number' | 'percent' | 'percentile' | 'formula' | 'autoMin' | 'autoMax'; /** Specifies the direction data bars are drawn, such as left to right. */ export declare type DataBarDirection = 'context' | 'leftToRight' | 'rightToLeft'; /** Specifies where data bars draw their axis, such as in the middle or not at all. */ export declare type DataBarAxisPosition = 'automatic' | 'middle' | 'none'; /** * Specifies the family of icons used by an icon set rule, such as three * arrows, five quarters, or an Excel extended family (`3Stars`, * `3Triangles`, `5Boxes`). * * The first seventeen values match transitional `ST_IconSetType` * (`sml.xsd`). `3Stars`, `3Triangles`, and `5Boxes` are [MS-XLSX] 2.7.10 * values and are stored on the x14 icon set, not on the transitional * attribute. Excel paints a same-count transitional fallback (`3Triangles` * → `3Signs`). `NoIcons` is not part of this union. */ export declare type IconSetType = '3Arrows' | '3ArrowsGray' | '3Flags' | '3TrafficLights1' | '3TrafficLights2' | '3Signs' | '3Symbols' | '3Symbols2' | '4Arrows' | '4ArrowsGray' | '4RedToBlack' | '4Rating' | '4TrafficLights' | '5Arrows' | '5ArrowsGray' | '5Rating' | '5Quarters' | '3Stars' | '3Triangles' | '5Boxes'; /** * Defines one end of a data bar range, specifying the value the shortest or * longest bar represents. * * `value` is required when `type` is `'number'`, `'percent'`, `'percentile'`, * or `'formula'`. */ export interface CfValuePoint { /** * How the endpoint's value is chosen — for example, the lowest or highest * value, a fixed number, or a formula. */ readonly type: CfThresholdType; /** * The endpoint's value, required unless `type` is `lowestValue` or * `highestValue`. */ readonly value?: string; } /** * Defines one anchor point in a color scale rule, specifying the value and * color used at that point of the gradient. * * `value` is required when `type` is `'number'`, `'percent'`, `'percentile'`, * or `'formula'`. */ export interface CfColorStop { /** * How the point's value is chosen — for example, the lowest value, a * fixed number, or a formula. */ readonly type: CfThresholdType; /** * The point's value, required unless `type` is `lowestValue` or * `highestValue`. */ readonly value?: string; /** The color shown where the scale reaches this point. */ readonly color: Color; } /** * Defines one threshold in an icon set rule, specifying the value a cell * must meet to receive that icon. * * When `greaterThanOrEqual` is `false`, the icon triggers on strictly * greater values instead of greater-than-or-equal. Default `true`. */ export interface CfIconCriterion { /** * How the threshold's value is chosen — for example, a fixed number, a * percentage, or a formula. */ readonly type: CfThresholdType; /** * The threshold's value, required unless `type` is `lowestValue` or * `highestValue`. */ readonly value?: string; /** Whether cells matching the threshold exactly trigger this icon. Default `true`. */ readonly greaterThanOrEqual?: boolean; } /** * Represents the data bar settings of a conditional formatting rule, * letting you draw in-cell bars whose length reflects each cell's value. * * Enable with `rule.type = 'dataBar'`, then configure properties on this handle. * There is no public bag/input type for data bars. */ export interface DataBar { /** The color the bars are drawn in. */ barColor: Color; /** The value the shortest bar represents. */ minPoint: CfValuePoint; /** The value the longest bar represents. */ maxPoint: CfValuePoint; /** The shortest bar's length, as a percentage of the cell width (0–100). */ minLength: number; /** The longest bar's length, as a percentage of the cell width (0–100). */ maxLength: number; /** * Whether the cell value remains visible next to its data bar. Set to * `false` to display the bar only. Default `true`. */ showValue: boolean; /** Whether a border is drawn around each bar. */ hasBorder: boolean; /** The border color, when bars have a border. */ borderColor: Color | undefined; /** Whether bars are drawn with a gradient fade. Default `true`. */ gradient: boolean; /** Which way the bars grow: with context, left to right, or right to left. */ dataBarDirection: DataBarDirection; /** Whether negative-value bars use the same fill color as positive bars. Default `false`. */ negativeBarColorSameAsPositive: boolean; /** * Fill color of the data bars drawn for negative values. Takes effect only * when `negativeBarColorSameAsPositive` is `false`; when `undefined`, the * viewer applies its built-in default (red in Excel). */ negativeFillColor: Color | undefined; /** Whether negative-value bars use the same border color as positive bars. Default `true`. */ negativeBarBorderColorSameAsPositive: boolean; /** * Border color of the data bars drawn for negative values. Takes effect * only when `hasBorder` is `true` and * `negativeBarBorderColorSameAsPositive` is `false`; otherwise the negative * bars reuse `borderColor`. When `undefined`, the viewer applies its * built-in default. */ negativeBorderColor: Color | undefined; /** Where the axis line between negative and positive bars is drawn. */ dataBarAxisPosition: DataBarAxisPosition; /** The color of the axis line, when shown. */ barAxisColor: Color | undefined; } /** * Represents the gradient configuration of a color scale rule, defining the * colors and values for its minimum, midpoint, and maximum. */ export interface ColorScale { /** The color and value at the low end of the scale. */ minPoint: CfColorStop; /** The optional middle color and value of the scale. Undefined for two-color scales. */ midPoint: CfColorStop | undefined; /** The color and value at the high end of the scale. */ maxPoint: CfColorStop; } /** * Represents the icon set settings of a conditional formatting rule, * letting you assign icons such as traffic lights or arrows based on each * cell's value. */ export interface IconSet { /** * The icon family the rule draws its icons from — for example * `'3TrafficLights1'` (red, yellow, green circles) or `'3Arrows'`. */ iconSetType: IconSetType; /** * The value thresholds that decide which icon each cell gets. One entry * per icon in the current `iconSetType` family, in low-to-high order. */ iconCriteria: CfIconCriterion[]; /** * Whether the cell value remains visible next to its icon. Set to * `false` to display the icon only. Default `true`. */ showValue: boolean; /** * Whether the thresholds in `iconCriteria` are percentages (of the * range's values) rather than absolute numbers. Default `true`. */ usePercent: boolean; /** * Whether the icon order is flipped, so the "best" icon marks the lowest * values instead of the highest. Default `false`. */ reverse: boolean; } /** * Sheet-level extension URI for `x14:conditionalFormattings`. * Citation: [MS-XLSX] extLst under worksheet; engineering pack samples. */ export declare const X14_CF_SHEET_EXT_URI = "{78C0D931-6437-407D-A8EE-F0AAD7539E65}"; /** * Rule-level extension URI for the GUID `id` pairing transitional ↔ x14. * Citation: [MS-XLSX] extLst under cfRule. */ export declare const X14_CF_RULE_ID_EXT_URI = "{B025F937-C7B1-47D3-B67F-A62EFF666E3E}"; /** * Represents a single conditional formatting rule, letting you choose how * cells are highlighted, colored, or ranked when their values meet a * condition. * * Configure scalars, formulas, format, and visual models on the returned handle after * {@link ConditionalFormats.add}. */ export interface ConditionalFormat { /** * The cell range the rule applies to, such as `A1:C10`. Multiple areas can * be listed separated by spaces. */ sqref: string; /** The kind of condition the rule tests, such as comparing values, ranking them, or matching text. */ type: ConditionalFormatType; /** The comparison the rule applies, such as greater-than or between. Used with value-comparison rule types. */ operator: ConditionalFormatOperator | undefined; /** The rule's formulas. Setting replaces the whole list at once. */ formulas: ReadonlyArray; /** * The rule's first formula — for example the threshold in a greater-than * rule. Clearing it removes the formula and shifts later ones forward. */ firstFormula: string | undefined; /** * The rule's second formula — for example the upper bound in a between * rule. Can only be set when `firstFormula` is set. */ secondFormula: string | undefined; /** * The rule's evaluation order. Lower numbers are evaluated first when * several rules overlap a cell. */ priority: number; /** * When `true` and this rule matches, Excel skips any lower-priority rules * for the same cell. */ stopIfTrue: boolean; /** The text a text-matching rule looks for. */ text: string | undefined; /** The time period a date-matching rule tests for, such as today or last week. */ timePeriod: ConditionalFormatTimePeriod | undefined; /** * Gets or sets the highlight formatting the rule applies when it matches * — font, fill, border, and number format. * * Read as {@link DifferentialFormatView}; write accepts * {@link DifferentialFormatInput}. Declared as a property for TypeScript 3.3 * interface compatibility (no get/set in interfaces). */ format: DifferentialFormatView | DifferentialFormatInput | undefined; /** How many cells a top-10 style rule affects, such as the top 10 values. */ rank: number | undefined; /** When `true`, a top-10 style rule treats `rank` as a percentage — e.g. rank `10` means the top 10%. */ percent: boolean; /** When `true`, a top-10 style rule targets the *bottom* values instead of the top. */ bottom: boolean; /** When `true`, an average rule highlights values *above* the average; when `false`, below it. */ aboveAverage: boolean; /** When `true`, an average rule also highlights cells that exactly equal the average. */ equalAverage: boolean; /** When set, an average rule highlights values this many standard deviations above or below the average. */ stdDev: number | undefined; /** * The rule's data bar settings. Available when the rule type is `dataBar`; * set `type = 'dataBar'` first to enable it. * * Property form for TypeScript 3.3 interface compatibility. Runtime setter * only accepts `undefined` (clear); enable via `type = 'dataBar'`. */ dataBar: DataBar | undefined; /** * The rule's color scale settings. Available when the rule type is * `colorScale`; set `type = 'colorScale'` first to enable it. * * Property form for TypeScript 3.3 interface compatibility. Runtime setter * only accepts `undefined` (clear); enable via `type = 'colorScale'`. */ colorScale: ColorScale | undefined; /** * The rule's icon set settings. Available when the rule type is `iconSet`; * set `type = 'iconSet'` first to enable it. * * Property form for TypeScript 3.3 interface compatibility. Runtime setter * only accepts `undefined` (clear); enable via `type = 'iconSet'`. */ iconSet: IconSet | undefined; } /** * Represents the collection of conditional formatting rules on a worksheet, * letting you add, find, and remove rules. * * Overlapping sqref is allowed; {@link add} always appends a default `cellIs` rule * for the given sqref. Configure type, formulas, format, and visuals on the handle. */ export interface ConditionalFormats { /** The number of rules on the worksheet. */ readonly count: number; /** Returns the rule at the given position, counted from zero. */ item(index: number): ConditionalFormat; /** * Adds a new rule covering the given cell range, starting as a simple * value-comparison rule, and returns it for configuration. * @throws InvalidArgumentError when sqref is empty/whitespace or not a string * @throws InvalidConditionalFormattingError when sqref tokens are invalid */ add(sqref: string): ConditionalFormat; /** Removes the rule at the given position, counted from zero. */ removeAt(index: number): void; /** Removes the given rule. Does nothing if it does not belong to this collection. */ remove(rule: ConditionalFormat): void; /** Removes every rule from the worksheet. */ clear(): void; /** * Returns every rule that covers the given cell, or an empty list if none. * @throws InvalidAddressError when address is not a single cell */ findByCell(address: string): ReadonlyArray; } /** Internal threshold point (includes gte flag used by iconSet cfvo). @private */ interface CfThresholdInternal { type: CfThresholdType; value: string | undefined; /** OOXML `CT_Cfvo/@gte` — default true; serialized only when false. */ gte: boolean; } /** Internal data-bar state (transitional + x14 extended fields). @private */ interface DataBarData { minPoint: CfThresholdInternal; maxPoint: CfThresholdInternal; barColor: Color; minLength: number; maxLength: number; showValue: boolean; /** x14 `@border` / XlsIO HasBorder. */ border: boolean; borderColor: Color | undefined; gradient: boolean; direction: DataBarDirection; negativeBarColorSameAsPositive: boolean; negativeFillColor: Color | undefined; negativeBarBorderColorSameAsPositive: boolean; negativeBorderColor: Color | undefined; axisPosition: DataBarAxisPosition; axisColor: Color | undefined; } /** One stop in an internal color-scale. @private */ interface ColorScaleStop { type: CfThresholdType; value: string | undefined; color: Color; } /** * Internal color-scale state. Preserves all parsed stops so that 4+ stop * scales survive round-trip even though the public API only exposes * min/mid/max. @private */ interface ColorScaleData { stops: ColorScaleStop[]; } /** Internal icon-set state. @private */ interface IconSetData { iconSetType: IconSetType; iconCriteria: CfThresholdInternal[]; showValue: boolean; usePercent: boolean; reverse: boolean; } /** * Internal wire entry for one `cfRule` (owns its parent sqref + pivot). * @private */ export interface ConditionalFormatEntry { ranges: CellRange[]; pivot: boolean; type: ConditionalFormatType; priority: number; stopIfTrue: boolean; operator: ConditionalFormatOperator | undefined; formulas: string[]; text: string | undefined; timePeriod: ConditionalFormatTimePeriod | undefined; rank: number | undefined; percent: boolean; bottom: boolean; aboveAverage: boolean; equalAverage: boolean; stdDev: number | undefined; /** * Zero-based index into stylesheet `dxfs` (`cfRule/@dxfId`). * Set via public `format` authoring or preserved on open. */ dxfId: number | undefined; /** Extra attributes excluding modeled ones (XML fragment, no leading space). */ extraAttrsXml: string; /** * Opaque child markup after modeled `formula` elements (extLst, unknown). * After TASK-1212 this no longer stores colorScale / dataBar / iconSet XML; * those live in structured fields. Rule-level x14 id pairing is stored in * {@link x14RuleId} rather than recomputed solely from this bag. */ childrenXml: string; /** Parent-level extra attrs excluding pivot/sqref (rare; preserved). */ parentExtraAttrsXml: string; /** Structured data-bar model; defined when `type === 'dataBar'`. */ dataBarData: DataBarData | undefined; /** Structured color-scale model; defined when `type === 'colorScale'`. */ colorScaleData: ColorScaleData | undefined; /** Structured icon-set model; defined when `type === 'iconSet'`. */ iconSetData: IconSetData | undefined; /** * Pairing GUID between transitional `cfRule` and x14 rule * (`ST_Guid`, with braces). Present when dual-written or loaded from x14. * Citation: [MS-XLSX] ext `{B025F937-…}` / x14 `cfRule/@id`. */ x14RuleId: string | undefined; } /** * Flat list of CF rules for worksheet XML model. * @private */ export interface ConditionalFormattingModel { readonly entries: ReadonlyArray; } /** * Host notifications for CF mutations. * @private */ export interface ConditionalFormatsHost { markDirty(): void; /** Workbook styles table (for differential format ensure/lookup). */ styles(): WorkbookStyles; } /** * Mutable conditional-formatting store. * @private */ export declare class ConditionalFormatsImpl implements ConditionalFormats { private readonly entries; private readonly handles; private host; constructor(initial?: ConditionalFormattingModel); /** @private */ bindHost(host: ConditionalFormatsHost): void; readonly count: number; list(): ReadonlyArray; get(index: number): ConditionalFormat; item(index: number): ConditionalFormat; add(sqref: string): ConditionalFormat; removeAt(index: number): void; remove(rule: ConditionalFormat): void; clear(): void; /** * True if any rule’s sqref contains the cell. * @throws InvalidAddressError when address is not a single cell * @private Not part of the published `ConditionalFormats` surface. */ has(address: string): boolean; findByCell(address: string): ReadonlyArray; /** * Replace contents from parse (does not mark dirty). * @private */ replaceFromParse(model: ConditionalFormattingModel): void; /** * Snapshot for serialize. * @private */ toModel(): ConditionalFormattingModel; /** * Merge x14 extended conditional formatting from worksheet after-sheet-data * opaque bag (extLst URI 78C0D931). Soft-pairs by GUID then by dataBar order. * @private */ applyX14FromAfterSheetData(afterSheetDataXml: ReadonlyArray | undefined): void; /** * Rewrite sheet-level x14 CF ext in after-sheet-data bag. Preserves other ext * entries and non-extLst siblings. Omits x14 ext when no dual-write rules. * @private */ rewriteAfterSheetDataXml(afterSheetDataXml: ReadonlyArray | undefined): string[]; private nextPriority; private applyModel; private requireStyles; private handleFor; } /** * Parse multi-area `ST_Sqref` into ordered ranges. * @throws InvalidConditionalFormattingError */ export declare function parseCfSqref(sqref: string): CellRange[]; /** * Format ranges as space-separated compact A1 sqref. */ export declare function formatCfSqref(ranges: ReadonlyArray): string; /** * CT_Worksheet local names that appear **before** `conditionalFormatting` after sheetData. * * Citation: transitional sml.xsd `CT_Worksheet`. */ export declare const CONDITIONAL_FORMATTING_PREDECESSORS_AFTER_SHEET_DATA: ReadonlyArray; /** * CT_Worksheet local names that appear **after** the CF block. * * Citation: transitional sml.xsd `CT_Worksheet`. */ export declare const CONDITIONAL_FORMATTING_SUCCESSORS: ReadonlyArray; /** * Index at which to insert the first serialized `conditionalFormatting` among * after-sheetData siblings. Subsequent CF parents insert immediately after the * previous one (caller inserts one-by-one or as a block). */ export declare function findConditionalFormattingInsertIndex(afterSheetDataLocals: ReadonlyArray): number; /** * Parse one `conditionalFormatting` element into zero or more entries. * Soft-skips individual bad cfRules (keep valid siblings). * @private */ export declare function parseConditionalFormattingXml(xml: string): ConditionalFormatEntry[]; /** * Serialize model to zero or more `conditionalFormatting` elements. * Returns empty array when no entries (caller omits). * @private */ export declare function serializeConditionalFormattingXml(model: ConditionalFormattingModel): string[]; export {};