/** * Worksheet data validations (`CT_DataValidations` / `CT_DataValidation`). * * Citations: * - ECMA-376-1 ยง18.3.1.33 `dataValidations` * - transitional sml.xsd `CT_DataValidations` / `CT_DataValidation` / * `ST_DataValidationType` / `ST_DataValidationOperator` / * `ST_DataValidationErrorStyle` / `ST_DataValidationImeMode` / `ST_Sqref` * - docs/specs/data-validations.md; docs/ooxml-mapping/data-validations.md * * Formulas are opaque text (never evaluated). `showListDropdown` is inverted * only at the wire (`showDropDown=true` hides the list UI). Overlapping target * addresses are allowed. Empty collection omits the parent element. * * Authoring default: {@link DataValidations.add} takes the target range and * returns a live handle; configure type, formulas, messages, and flags on the * handle. New rules start with `showErrorMessage = true`, matching Excel/XlsIO * ("Show error alert after invalid data is entered"). The XSD wire-level * default for `showErrorMessage` is `false` (attribute omitted), but this * library's authoring API opts new rules in explicitly instead of silently * mirroring the omitted-attribute default. */ import { CellRange } from '../address/cell-address'; /** * Specifies what kind of input a validation rule accepts, such as whole * numbers, dates, or a list of values. */ export declare type DataValidationType = 'none' | 'whole' | 'decimal' | 'list' | 'date' | 'time' | 'textLength' | 'custom'; /** * Specifies the comparison a validation rule applies to entered values, * such as between or greater than. */ export declare type DataValidationOperator = 'between' | 'notBetween' | 'equal' | 'notEqual' | 'lessThan' | 'lessThanOrEqual' | 'greaterThan' | 'greaterThanOrEqual'; /** * Specifies what happens when a user enters invalid data: block it, warn, * or just inform. */ export declare type DataValidationErrorStyle = 'stop' | 'warning' | 'information'; /** * Controls the behavior of a device's input method editor (IME) when the * validated cell is selected. * * Wire/preserve detail for `ST_DataValidationImeMode` โ€” not part of the * shipped package surface (`stripInternal`). * * @private */ export declare type DataValidationImeMode = 'noControl' | 'off' | 'on' | 'disabled' | 'hiragana' | 'fullKatakana' | 'halfKatakana' | 'fullAlpha' | 'halfAlpha' | 'fullHangul' | 'halfHangul'; /** * Represents a data validation rule applied to cells, letting you control * what values users can enter and the prompts or error alerts they see. */ export interface DataValidation { /** * The cell or range the rule applies to, written as an A1-style address. * Multiple areas are separated by spaces (e.g. `'A1:A5 C1:C5'`). Assign a * new address to apply the rule to different cells. */ address: string; /** * The kind of value the rule accepts โ€” for example `'whole'` allows only * whole numbers, `'decimal'` only decimal numbers, and `'list'` only the * values in `listValues` or `firstFormula`. Default `'none'`. */ type: DataValidationType; /** * How entered data is compared against `firstFormula` (and `secondFormula` when * `'between'` or `'notBetween'`). Default `'between'`. */ operator: DataValidationOperator; /** * How Excel responds to invalid data: `'stop'` rejects the entry, while * `'warning'` and `'information'` let the user keep or discard it. * Default `'stop'`. */ errorStyle: DataValidationErrorStyle; /** * The Input Method Editor (IME) behavior for the cells, used when entering * East-Asian text. Default `'noControl'`. * Wire detail โ€” not part of the shipped package surface (`stripInternal`). * * @private */ imeMode: DataValidationImeMode; /** * Whether blank cells are treated as valid input, bypassing the rule's * check. Default `false`. */ allowBlank: boolean; /** * Whether the cell shows a dropdown arrow that lets users pick from the * list. Applies when `type` is `'list'`. Default `true`. */ showListDropdown: boolean; /** * Whether Excel shows `prompt` (titled `promptTitle`, when set) when one * of the rule's cells is selected. Default `false`. */ showInputMessage: boolean; /** * Whether Excel shows the error alert when invalid data is entered. * Default `true` on new rules. */ showErrorMessage: boolean; /** The title of the error alert. */ errorTitle: string | undefined; /** The message shown in the error alert when invalid data is entered. */ error: string | undefined; /** The title of the input message. */ promptTitle: string | undefined; /** The message shown next to a cell when it is selected. */ prompt: string | undefined; /** * The value, cell reference, or formula that entered data is compared * against. For `'list'` rules this is the list source; for `'between'` * and `'notBetween'` it is the lower bound, paired with `secondFormula`. */ firstFormula: string | undefined; /** * The upper bound paired with `firstFormula`, used only when `operator` is * `'between'` or `'notBetween'`. */ secondFormula: string | undefined; /** * The values a user can pick from when `type` is `'list'`. Setting this * encodes the values into `firstFormula`; reading it decodes `firstFormula` back * into values when it is an inline quoted list. */ listValues: ReadonlyArray | undefined; } /** * Represents the collection of data validation rules on a worksheet, letting * you add, list, and remove rules. * * Overlapping target addresses are allowed; {@link add} always appends a * default rule for the given range. Configure type, formulas, messages, and * flags on the returned handle. */ export interface DataValidations { /** The number of data-validation rules on the worksheet. */ readonly count: number; /** * Whether Excel suppresses input messages for the whole worksheet, * overriding each rule's own `showInputMessage`. Default `false`. */ disablePrompts: boolean; /** * The horizontal position (in pixels) of the input-message prompt window, * relative to the workbook window. `undefined` leaves the placement to * Excel. * @private Not part of the published package surface; preserved on load/save. */ xWindow: number | undefined; /** * The vertical position (in pixels) of the input-message prompt window, * relative to the workbook window. `undefined` leaves the placement to * Excel. * @private Not part of the published package surface; preserved on load/save. */ yWindow: number | undefined; /** * Get all data-validation rules as a list, in the order they appear on * the worksheet. * * @returns the current data-validation rules. */ list(): ReadonlyArray; /** * Get the data-validation rule at a zero-based position, in the order the * rules appear on the worksheet. * * @param index - The zero-based position of the rule. * @returns the rule at `index`. * @throws InvalidArgumentError when the index is out of range */ get(index: number): DataValidation; /** * Add a data-validation rule to the worksheet. * * @param input - The settings for the new rule, including the cells it * applies to. * @returns the newly created rule. * @throws InvalidArgumentError when required fields are empty/wrong type * @throws InvalidDataValidationError when address/enums/list source invalid */ add(address: string): DataValidation; /** * Remove the data-validation rule at a zero-based position. * * @param index - The zero-based position of the rule to remove. * @throws InvalidArgumentError when the index is out of range */ removeAt(index: number): void; /** * Remove a data-validation rule previously returned by this collection. * * @param rule - The rule to remove. * @throws InvalidArgumentError when the rule was not created by this * collection */ remove(rule: DataValidation): void; /** Remove every data-validation rule from the worksheet. */ clear(): void; /** * Check whether any rule applies to the given cell. * * @param address - The address of a single cell, like `'C3'`. * @returns `true` when at least one rule's range contains the cell. * @private Not part of the published package surface; use {@link findByCell}. * @throws InvalidAddressError when address is not a single cell */ has(address: string): boolean; /** * Get every rule that applies to the given cell, in worksheet order. * * @param address - The address of a single cell, like `'C3'`. * @returns the rules whose range contains the cell. * @throws InvalidAddressError when address is not a single cell */ findByCell(address: string): ReadonlyArray; } /** * Internal wire entry for one `dataValidation`. * @private */ export interface DataValidationEntry { ranges: CellRange[]; type: DataValidationType; operator: DataValidationOperator; errorStyle: DataValidationErrorStyle; imeMode: DataValidationImeMode; allowBlank: boolean; /** Public intent (true = show dropdown). Wire showDropDown = !showListDropdown. */ showListDropdown: boolean; showInputMessage: boolean; showErrorMessage: boolean; errorTitle: string | undefined; error: string | undefined; promptTitle: string | undefined; prompt: string | undefined; firstFormula: string | undefined; secondFormula: string | undefined; listValues: string[] | undefined; /** Extra attributes excluding modeled ones (XML fragment, no leading space). */ extraAttrsXml: string; } /** * Container-level attrs + rules for worksheet XML model. * @private */ export interface DataValidationsModel { readonly disablePrompts: boolean; readonly xWindow: number | undefined; readonly yWindow: number | undefined; readonly extraAttrsXml: string; readonly entries: ReadonlyArray; } /** * Host notifications for DV mutations. * @private */ export interface DataValidationsHost { markDirty(): void; } /** * Mutable data-validations store. * @private */ export declare class DataValidationsImpl implements DataValidations { private readonly entries; private readonly handles; private host; private _disablePrompts; private _xWindow; private _yWindow; private _extraAttrsXml; constructor(initial?: DataValidationsModel); /** @private */ bindHost(host: DataValidationsHost): void; readonly count: number; /** @private */ /** @private */ disablePrompts: boolean; /** @private */ /** @private */ xWindow: number | undefined; /** @private */ /** @private */ yWindow: number | undefined; list(): ReadonlyArray; get(index: number): DataValidation; add(address: string): DataValidation; removeAt(index: number): void; remove(rule: DataValidation): void; clear(): void; /** @private */ has(address: string): boolean; findByCell(address: string): ReadonlyArray; /** * Replace contents from parse (does not mark dirty). * @private */ replaceFromParse(model: DataValidationsModel): void; /** * Snapshot for serialize. * @private */ toModel(): DataValidationsModel; private applyModel; private handleFor; } /** * Parse multi-area `ST_Sqref` into ordered ranges. * @throws InvalidDataValidationError */ export declare function parseSqref(sqref: string): CellRange[]; /** * Format ranges as space-separated compact A1 sqref. */ export declare function formatSqref(ranges: ReadonlyArray): string; /** * Encode list values as Excel inline list formula (`"a,b,c"`). * Quotes doubled inside values; whole formula wrapped in double quotes. */ export declare function encodeListFormula(values: ReadonlyArray): string; /** * Decode Excel inline list formula when it is a quoted CSV; else undefined. */ export declare function tryDecodeListFormula(formula: string): string[] | undefined; /** * CT_Worksheet local names that appear **before** `dataValidations` after sheetData. * * Citation: transitional sml.xsd `CT_Worksheet`. */ export declare const DATA_VALIDATIONS_PREDECESSORS_AFTER_SHEET_DATA: ReadonlyArray; /** * CT_Worksheet local names that appear **after** `dataValidations`. * * Citation: transitional sml.xsd `CT_Worksheet`. */ export declare const DATA_VALIDATIONS_SUCCESSORS: ReadonlyArray; /** * Index at which to insert serialized `dataValidations` among after-sheetData siblings. */ export declare function findDataValidationsInsertIndex(afterSheetDataLocals: ReadonlyArray): number; /** * Parse `dataValidations` element XML into a model. * Soft-skips individual bad rules (keep valid siblings). * @private */ export declare function parseDataValidationsXml(xml: string): DataValidationsModel; /** * Serialize model to a `dataValidations` element, or `undefined` when empty. * @private */ export declare function serializeDataValidationsXml(model: DataValidationsModel): string | undefined;