/** * Public Cell handle bound to a worksheet address. * * Citations: docs/specs/worksheet-cells.md; docs/requirements/worksheet-cells.md; * docs/specs/styles-table.md (style / numberFormat); * docs/specs/cell-formulas.md (formula); * docs/specs/hyperlinks.md (hyperlink); * docs/api/API-RULES.md R1.1 / R1.4 / R1.5 (one public name per process). * * Formula APIs are text-only: the library never evaluates formulas and never * resolves external workbook links. Value setters never promote strings * beginning with `=`, `+`, `-`, or `@` into formulas. */ import { CellStyle, CellFormat } from '../styles/styles-xml'; import { WorksheetImpl } from '../workbook/worksheet'; import { AddCommentOptions, Comment } from '../worksheet/comments'; import { CellHyperlink } from '../worksheet/hyperlinks'; import { ThreadedComment } from '../worksheet/threaded-comments'; import { CellFormula, ClearFormulaOptions, SetFormulaOptions } from './formula'; import { RichTextString } from './rich-text'; import { CellValue } from './types'; /** * Represents a single cell in a worksheet, allowing you to read, write, and * format its contents. Obtain it via {@link Worksheet.getCell}. */ export declare class Cell { private readonly sheet; private readonly row; private readonly col; /** @private */ constructor(sheet: WorksheetImpl, row: number, col: number); /** * Returns the cell's reference, such as `B2`. */ readonly address: string; /** * Gets or sets the cell's contents — a number, text, boolean, or error * value — or `null` when the cell is empty. Setting a value replaces any * formula. For formula cells, reading returns the saved result; the * formula is never recalculated. */ /** * Set a plain value. Clears any formula on this cell. Text is stored * as-is; even text that looks like a formula is never turned into one. * @throws InvalidCellValueError | InvalidErrorCodeError */ value: CellValue; /** * Gets or sets the cell's text. Returns `null` when the cell is empty or * holds a different type. Text is stored as-is, even when it looks like a * formula. */ /** * Assign plain text, or `null` to clear. * @throws InvalidCellValueError when value is not a string or null */ text: string | null; /** * Gets or sets the cell's numeric value, including dates stored as * numbers. Returns `null` when the cell is empty or holds a different * type. */ /** * Assign a finite number, or `null` to clear. * @throws InvalidCellValueError when value is not a finite number or null */ number: number | null; /** * Gets or sets the cell's date and time as a `Date` object. Returns * `null` when the cell is empty or holds a non-date. Setting a date also * applies a default date number format so Excel displays it correctly. */ /** * Assign a valid `Date` (stores serial + datetime number format), or `null` to clear. * @throws InvalidCellValueError when value is not a valid Date or null */ dateTime: Date | null; /** * Formula text and attributes when `f` is present; `undefined` otherwise. * * Text-only: never evaluates. Shared/array metadata (`t`/`ref`/`si` and * other attributes) are exposed as stored. * * Citations: ECMA-376-1 §18.3.1.40; docs/specs/cell-formulas.md. * Prefer public {@link formula} for normal expressions; use this for shared/array metadata. * * * * @private */ getFormula(): CellFormula | undefined; /** * Set formula **text** on this cell. Does not evaluate. Does not resolve * external links. Does not write the expression through the shared string * table as the formula source. * * A single leading `=` is stripped as a convenience (Excel stores the bare * expression in `f`). Strings set via {@link value} are never promoted. * * By default clears the cached calculated value so Excel recalculates on open. * Prior shared/array `si`/`ref` are replaced unless supplied in `options`. * * @throws InvalidFormulaError when expression is empty (for normal type) or type is invalid * * Citations: ECMA-376-1 §18.3.1.40; docs/specs/cell-formulas.md. * Prefer public {@link formula} for normal expression set/clear. * * * * @private */ setFormula(expression: string, options?: SetFormulaOptions): void; /** * Remove `f` from this cell. By default leaves any cached `v` intact. * * Citations: docs/specs/cell-formulas.md. * Prefer `formula = undefined` for the public clear path. * * * * @private */ clearFormula(options?: ClearFormulaOptions): void; /** * Zero-based `cellXfs` index (`c@s`), or `undefined` when absent. * * Citations: ECMA-376-1 §18.3.1.4; docs/specs/styles-table.md. * Prefer public {@link style} / {@link numberFormat}. * * * * @private */ /** * Assign or clear the cell style index. Does not clear value or formula. * Out-of-range indexes throw {@link InvalidStyleIndexError}. * * @throws InvalidStyleIndexError when index is outside `cellXfs` * Prefer public {@link style}. * * * * @private */ styleIndex: number | undefined; /** * Ensure a `cellXfs` row for `style` and assign {@link styleIndex}. * Preserves the current value. * * Citations: docs/specs/styles-table.md; ECMA-376-1 §18.8.10. * Prefer public {@link style}. * * * * @private */ applyStyle(style: CellStyle): void; /** * Gets or sets the cell's formula, such as `SUM(A1:A10)`. Set to * `undefined` to remove the formula while keeping its last calculated * result. Formulas are stored as written and are never evaluated. */ /** * Set or clear formula text. `undefined` clears `f` (leaves cached `v`). * @throws InvalidFormulaError when expression is empty after normalize */ formula: string | undefined; /** * Hyperlink for this cell address, or `undefined` when none. * * Sole public cell hyperlink surface (API-RULES R1.5). `displayText` maps to * `display` (XlsIO TextToDisplay) and also sets this cell's value so the * text is visible in Excel. Optional `type` / `subAddress` match XlsIO * Type / SubAddress. `clear()` does not remove the hyperlink. Distinct * from the `HYPERLINK()` formula text on {@link formula}. * * Citations: ECMA-376-1 §18.3.1.47; docs/specs/hyperlinks.md; API-RULES R1.5 / R5.1. */ /** * Gets or sets the clickable link attached to this cell. Set to * `undefined` to remove the link. Removing the link does not clear the * cell's value. * * @throws InvalidHyperlinkError when target/ref is invalid * @throws InvalidArgumentError when value shape is wrong */ hyperlink: CellHyperlink | undefined; /** * Discussion thread on this cell, or `undefined` if none. * Create one with {@link addThreadedComment}. */ readonly threadedComment: ThreadedComment | undefined; /** * Start a discussion thread on this cell and return it so you can add replies. * A cell can have only one thread. * * @param text - Opening message text. * @param author - Author display name. Default `""`. * @param createdAt - When the thread started. Default: now. * * @throws InvalidThreadedCommentError when the cell already has a thread * @throws InvalidArgumentError when text is invalid */ addThreadedComment(text: string, author?: string, createdAt?: Date): ThreadedComment; /** * Classic sticky note on this cell, or `undefined` if none. */ /** * Replace or clear the classic note on this cell. * Assign note options to create or replace it; assign `undefined` to remove it. * Cell path ignores {@link AddCommentOptions.ref} / row / column; the cell is the target. */ comment: Comment | AddCommentOptions | undefined; /** * Add a classic sticky note on this cell. * * Cell path ignores {@link AddCommentOptions.ref} / row / column; the cell is the target. * * @throws InvalidCommentError when options are invalid or the cell already has a note */ addComment(options?: AddCommentOptions): Comment; /** * Remove the classic sticky note from this cell (does nothing if there is none). */ removeComment(): void; /** * `true` when this cell uses rich text (different formatting on parts of the value). */ readonly hasRichText: boolean; /** * Rich text for this cell — full text and character ranges you can format. * * Example: `cell.richText.characters(0, 4).font = workbook.createFont()`. */ readonly richText: RichTextString; /** * Gets or sets the cell's formatting — number format, font, fill, border, * alignment, and protection — in one operation. Set to `undefined` to * clear the cell's formatting without affecting its value. */ /** * Apply a style input or clear the cell style index. */ style: CellFormat | undefined | CellStyle; /** * Host callbacks for {@link RichTextString} / {@link RichTextCharacters}. */ private createRichTextHost; private getRichPlainText; private getRichRunsFromModel; private computeHasRichFormatting; /** * Commit structured runs: plain single-run → plain SST; formatted/multi → rich SST. * Always clears inline bags and promotes authored content to shared strings. */ private commitRichRuns; /** * Gets or sets the number format code that controls how the cell's value * is displayed, such as `#,##0.00` or `yyyy-mm-dd`. * * On read: resolves via styles `numFmts` rows first, then the ECMA-376-1 * §18.8.30 implied built-in table when the cell's `numFmtId` is a known * language-neutral built-in (for example id 14 → `m/d/yyyy`). Returns * `undefined` when the cell has no style/`numFmtId`, or the id has no * package row and no built-in mapping. Setting always allocates a custom * format (≥164) and does not rewrite built-in ids. */ /** * Assign a custom number format code on this cell. * @throws InvalidNumberFormatError when code is empty / whitespace-only */ numberFormat: string | undefined; /** * Removes the cell's value and formula, leaving its formatting in place. * Does nothing when the cell is already empty of both. */ clear(): void; private adjustSstRefIfNeeded; }