/** * Worksheet merged ranges (`CT_MergeCells` / `CT_MergeCell@ref`). * * Citations: * - ECMA-376-1 §18.3.1.55 `mergeCells` / §18.3.1.56 `mergeCell` * - transitional sml.xsd `CT_MergeCells` / `CT_MergeCell` / `ST_Ref` * - docs/specs/merged-cells.md; docs/ooxml-mapping/merged-cells.md * * Meaningful cell content for a merge lives in the **top-left** cell. * This API does not move, clear, or rewrite covered cell values on add/remove. */ import { InvalidMergeRefError } from '../core/errors'; /** * Defines a rectangular block of cells as the bounds of a merged region, * from its first to last row and column. */ export interface MergeRange { /** The first row of the merged area — 1-based, like Excel rows. */ readonly startRow: number; /** The first column of the merged area — 1-based, like Excel columns. */ readonly startCol: number; /** The last row of the merged area — 1-based, inclusive. */ readonly endRow: number; /** The last column of the merged area — 1-based, inclusive. */ readonly endCol: number; } /** * Represents the merged cell regions in a worksheet, letting you merge, * find, and unmerge ranges of cells. * * Exact-ref `has` / `remove` use normalized compact A1 (`A1` or `A1:B2`). * Overlapping adds are rejected; exact same normalized ref is idempotent. */ export interface MergedCells { /** The number of merged areas on the worksheet. */ readonly count: number; /** * Get all merged areas as a list of A1 range addresses, in the order * they appear on the worksheet. * * @returns the current merged-area addresses. */ list(): ReadonlyArray; /** * Check whether the worksheet contains a merged area with exactly this * address. * * @param ref - The range address to look for, like `'A1:B2'`. * @returns `true` when a merged area with the exact address exists. */ has(ref: string): boolean; /** * Merge the cells in a range into a single area. The area's content is * kept in its top-left cell, as in Excel. * * @param ref - The range to merge, like `'A1:B2'`. * @throws InvalidArgumentError when `ref` is empty/whitespace * @throws InvalidMergeRefError when the ref is unparseable or inverted * @throws MergeOverlapError when the range overlaps an existing merge * (the exact same address is a no-op, not an overlap) */ add(ref: string): void; /** * Remove the merged area with exactly this address. The cells keep their * values; only the merge is removed. * * @param ref - The range address to remove, like `'A1:B2'`. */ remove(ref: string): void; /** Remove every merged area on the worksheet. Cell values are kept. */ clear(): void; } /** * Opaque extras on a single `mergeCell` for round-trip. * @private */ export interface MergeCellEntry { readonly range: MergeRange; /** Extra attributes excluding `ref` (XML fragment without leading space). */ readonly extraAttrsXml: string; } /** * Host notifications for merge mutations. * @private */ export interface MergedCellsHost { markDirty(): void; } /** * Mutable merged-cells store backed by an ordered entry list. * @private */ export declare class MergedCellsImpl implements MergedCells { private readonly entries; private host; constructor(initial?: ReadonlyArray); /** @private */ bindHost(host: MergedCellsHost): void; readonly count: number; list(): ReadonlyArray; has(ref: string): boolean; add(ref: string): void; remove(ref: string): void; clear(): void; /** * Replace contents from parse (does not mark dirty). * @private */ replaceFromParse(entries: ReadonlyArray): void; /** * Snapshot for serialize. * @private */ toEntries(): ReadonlyArray; } /** * Axis-aligned bounding box overlap (inclusive edges). * Touching edges count as overlap (Excel merges share boundary cells). */ export declare function rangesOverlap(a: MergeRange, b: MergeRange): boolean; /** * Normalize a user/file ref to compact uppercase A1 key. * @throws InvalidMergeRefError / InvalidArgumentError via parse path */ export declare function normalizeMergeRefKey(ref: string): string; /** * CT_Worksheet local names that appear **before** `mergeCells` after `sheetData` * (schema sequence order). * * Citation: transitional sml.xsd `CT_Worksheet`. */ export declare const MERGE_CELLS_PREDECESSORS_AFTER_SHEET_DATA: ReadonlyArray; /** * CT_Worksheet local names that appear **after** `mergeCells`. * * Citation: transitional sml.xsd `CT_Worksheet`. */ export declare const MERGE_CELLS_SUCCESSORS: ReadonlyArray; /** * Index at which to insert serialized `mergeCells` among after-sheetData siblings. * * Prefer: after the last known predecessor present; else before the first known * successor; else append. Unknown elements keep relative order. */ export declare function findMergeCellsInsertIndex(afterSheetDataLocals: ReadonlyArray): number; /** * Parse `mergeCells` element XML into ordered entries. * Soft-skips individual bad `mergeCell@ref` values (keep valid siblings). * @private */ export declare function parseMergeCellsXml(mergeCellsXml: string): MergeCellEntry[]; /** * Serialize merge entries to a `mergeCells` element, or `undefined` when empty. * @private */ export declare function serializeMergeCellsXml(entries: ReadonlyArray): string | undefined; export { InvalidMergeRefError };