/** * Type definitions for ExcelTS * This file exports all public types used by the library */ export type Buffer = Uint8Array; export declare enum PaperSize { Legal = 5, Executive = 7, A4 = 9, A5 = 11, B5 = 13, Envelope_10 = 20, Envelope_DL = 27, Envelope_C5 = 28, Envelope_B5 = 34, Envelope_Monarch = 37, Double_Japan_Postcard_Rotated = 82, K16_197x273_mm = 119 } export interface Color { argb: string; theme: number; } export interface Font { name: string; size: number; family: number; scheme: "minor" | "major" | "none"; charset: number; color: Partial; bold: boolean; italic: boolean; underline: boolean | "none" | "single" | "double" | "singleAccounting" | "doubleAccounting"; vertAlign: "superscript" | "subscript"; strike: boolean; outline: boolean; condense: boolean; extend: boolean; shadow: boolean; } export interface Alignment { horizontal: "left" | "center" | "right" | "fill" | "justify" | "centerContinuous" | "distributed"; vertical: "top" | "middle" | "bottom" | "distributed" | "justify"; wrapText: boolean; shrinkToFit: boolean; indent: number; readingOrder: "rtl" | "ltr"; textRotation: number | "vertical"; } export interface Protection { locked: boolean; hidden: boolean; } export type BorderStyle = "thin" | "dotted" | "hair" | "medium" | "double" | "thick" | "dashed" | "dashDot" | "dashDotDot" | "slantDashDot" | "mediumDashed" | "mediumDashDotDot" | "mediumDashDot"; export interface Border { style: BorderStyle; color: Partial; } export interface BorderDiagonal extends Border { up: boolean; down: boolean; } export interface Borders { top: Partial; left: Partial; bottom: Partial; right: Partial; diagonal: Partial; } export type FillPatterns = "none" | "solid" | "darkVertical" | "darkHorizontal" | "darkGrid" | "darkTrellis" | "darkDown" | "darkUp" | "lightVertical" | "lightHorizontal" | "lightGrid" | "lightTrellis" | "lightDown" | "lightUp" | "darkGray" | "mediumGray" | "lightGray" | "gray125" | "gray0625"; export interface FillPattern { type: "pattern"; pattern: FillPatterns; fgColor?: Partial; bgColor?: Partial; } export interface GradientStop { position: number; color: Partial; } export interface FillGradientAngle { type: "gradient"; gradient: "angle"; degree: number; stops: GradientStop[]; } export interface FillGradientPath { type: "gradient"; gradient: "path"; center: { left: number; top: number; }; stops: GradientStop[]; } export type Fill = FillPattern | FillGradientAngle | FillGradientPath; export interface NumFmt { id: number; formatCode: string; } interface StyleBase { font: Partial; alignment: Partial; protection: Partial; border: Partial; fill: Fill; } export interface StyleInput extends StyleBase { numFmt: string; } export interface StyleOutput extends StyleBase { numFmt: NumFmt; } export interface Style extends StyleBase { numFmt: string | NumFmt; } export interface Margins { top: number; left: number; bottom: number; right: number; header: number; footer: number; } export interface PageSetup { margins: Margins; orientation: "portrait" | "landscape"; horizontalDpi: number; verticalDpi: number; fitToPage: boolean; fitToWidth: number; fitToHeight: number; scale: number; pageOrder: "downThenOver" | "overThenDown"; blackAndWhite: boolean; draft: boolean; cellComments: "atEnd" | "asDisplayed" | "None"; errors: "dash" | "blank" | "NA" | "displayed"; paperSize: PaperSize; showRowColHeaders: boolean; showGridLines: boolean; firstPageNumber: number; horizontalCentered: boolean; verticalCentered: boolean; printArea: string; printTitlesRow: string; printTitlesColumn: string; } export interface HeaderFooter { differentFirst: boolean; differentOddEven: boolean; oddHeader: string; oddFooter: string; evenHeader: string; evenFooter: string; firstHeader: string; firstFooter: string; } export interface WorksheetViewCommon { rightToLeft?: boolean; activeCell?: string; showRuler?: boolean; showRowColHeaders?: boolean; showGridLines?: boolean; zoomScale?: number; zoomScaleNormal?: number; } export interface WorksheetViewNormal { state: "normal"; style: "pageBreakPreview" | "pageLayout"; } export interface WorksheetViewFrozen { state: "frozen"; style?: "pageBreakPreview"; xSplit?: number; ySplit?: number; topLeftCell?: string; } export interface WorksheetViewSplit { state: "split"; style?: "pageBreakPreview" | "pageLayout"; xSplit?: number; ySplit?: number; topLeftCell?: string; activePane?: "topLeft" | "topRight" | "bottomLeft" | "bottomRight"; } export type WorksheetView = WorksheetViewCommon & (WorksheetViewNormal | WorksheetViewFrozen | WorksheetViewSplit); export interface WorksheetProperties { tabColor: Partial; outlineLevelCol: number; outlineLevelRow: number; outlineProperties: { summaryBelow: boolean; summaryRight: boolean; }; defaultRowHeight: number; defaultColWidth?: number; dyDescent?: number; showGridLines: boolean; } export type WorksheetState = "visible" | "hidden" | "veryHidden"; export type AutoFilter = string | { from: string | { row: number; col: number; }; to: string | { row: number; col: number; }; }; export interface WorksheetProtection { objects: boolean; scenarios: boolean; selectLockedCells: boolean; selectUnlockedCells: boolean; formatCells: boolean; formatColumns: boolean; formatRows: boolean; insertColumns: boolean; insertRows: boolean; insertHyperlinks: boolean; deleteColumns: boolean; deleteRows: boolean; sort: boolean; autoFilter: boolean; pivotTables: boolean; spinCount: number; } export interface WorkbookView { x: number; y: number; width: number; height: number; firstSheet: number; activeTab: number; visibility: string; } export interface WorkbookProperties { date1904: boolean; } export interface WorkbookProtection { lockStructure: boolean; lockWindows: boolean; lockRevision: boolean; spinCount: number; } export interface CalculationProperties { fullCalcOnLoad: boolean; /** Enable iterative calculation for circular references */ iterate?: boolean; /** Maximum number of iterations (default 100) */ iterateCount?: number; /** Convergence threshold (default 0.001) */ iterateDelta?: number; } export interface CellErrorValue { error: "#N/A" | "#REF!" | "#NAME?" | "#DIV/0!" | "#NULL!" | "#VALUE!" | "#NUM!" | "#SPILL!" | "#CALC!"; } export interface RichText { text: string; font?: Partial; } export interface CellRichTextValue { richText: RichText[]; } export interface CellHyperlinkValue { /** * Plain-text display for the hyperlink. Always a string. * * When `richText` is also set, this field mirrors the concatenated * `.text` of every run in `richText` (flattened representation). */ text: string; /** * Optional rich-text runs providing formatted display for the hyperlink. * When present, `text` must equal the concatenation of each run's `.text`. */ richText?: RichText[]; hyperlink: string; tooltip?: string; } /** * Input shape for assigning a hyperlink cell value. * * Accepts either: * - a plain-text hyperlink (`text + hyperlink`), OR * - a rich-text hyperlink (`richText + hyperlink`) — `text` is auto-derived * by flattening the runs, so callers do not have to repeat it. * * The output shape (`CellHyperlinkValue` returned from `cell.value`) always * has `text: string` populated. */ export type CellHyperlinkValueInput = { text: string; richText?: RichText[]; hyperlink: string; tooltip?: string; } | { text?: string; richText: RichText[]; hyperlink: string; tooltip?: string; }; /** * Input shape for assigning a formula cell that also carries a hyperlink. * * Loaded workbooks may present a formula cell with an attached hyperlink * (e.g. `=HYPERLINK(...)` style or a `` entry pointing * at a formula cell). On the public surface such cells are classified as * Hyperlink (`cell.type === ValueType.Hyperlink`) with the formula's result * as display text, while `cell.model.formula` is preserved for round-trip. * * Use this shape to construct that combination directly without going * through `cell.model`. */ export interface CellFormulaHyperlinkValue { formula: string; result?: number | string | boolean | Date | CellErrorValue; hyperlink: string; tooltip?: string; } export interface CellFormulaValue { formula: string; result?: number | string | boolean | Date | CellErrorValue; date1904?: boolean; } /** Array formula that spans multiple cells */ export interface CellArrayFormulaValue { formula: string; result?: number | string | boolean | Date | CellErrorValue; /** Must be "array" for array formulas */ shareType: "array"; /** The range this array formula applies to, e.g. "A1:B2" */ ref: string; /** * Mark this as an Excel 365 dynamic array formula (FILTER, SORT, UNIQUE, etc.). * Dynamic array formulas differ from legacy CSE (Ctrl+Shift+Enter) array formulas: * - The `ref` typically points to the formula cell itself (spill is dynamic) * - Excel writes a `cm` attribute on the `` element linking to `xl/metadata.xml` * - The metadata marks the formula with `` */ isDynamicArray?: boolean; } export interface CellSharedFormulaValue { sharedFormula: string; readonly formula?: string; result?: number | string | boolean | Date | CellErrorValue; date1904?: boolean; } export interface CellCheckboxValue { /** Indicates this is a checkbox value */ checkbox: boolean; } export type CellValue = null | number | string | boolean | Date | undefined | CellErrorValue | CellRichTextValue | CellHyperlinkValue | CellFormulaValue | CellArrayFormulaValue | CellSharedFormulaValue | CellCheckboxValue; /** * Input variant of {@link CellValue} used when assigning to `cell.value`. * * Accepts the same shapes as `CellValue` plus more permissive forms that * the runtime normalizes: * - `CellHyperlinkValueInput` — rich-text hyperlinks may omit `text` * (it will be derived from `richText`). * - `CellFormulaHyperlinkValue` — formula cells may carry a `hyperlink`. * * `cell.value` (the getter) still returns the canonical `CellValue` shape. */ export type CellValueInput = null | number | string | boolean | Date | undefined | CellErrorValue | CellRichTextValue | CellHyperlinkValueInput | CellFormulaValue | CellArrayFormulaValue | CellSharedFormulaValue | CellCheckboxValue | CellFormulaHyperlinkValue; export interface CommentMargins { insetmode: "auto" | "custom"; inset: number[]; } export interface CommentProtection { locked: "True" | "False"; lockText: "True" | "False"; } export type CommentEditAs = "twoCells" | "oneCells" | "absolute"; export interface Comment { texts?: RichText[]; margins?: Partial; protection?: Partial; editAs?: CommentEditAs; /** * Office 365 threaded-comment conversation anchored at the same * cell. When present, Excel surfaces the modern reply UI; the * classic VML note still renders as a fallback for older viewers. * * The first entry in the list is the top-level comment; subsequent * entries with `parentId === first.id` are replies to it. Nested * threads beyond two levels are not supported by Excel itself. */ threadedComments?: ThreadedComment[]; } /** * A single entry in a threaded-comment conversation * (`xl/threadedComments/threadedComment{N}.xml` → * ``). * * `id` is a GUID-braced string Excel expects to uniquely identify the * comment within the sheet; callers may omit it and let the writer * synthesise one. `personId` must reference an entry in the * workbook-level {@link ThreadedCommentPerson} list — the writer * enforces this by adding any dangling `personId` to the list with a * placeholder displayName. */ export interface ThreadedComment { /** `{GUID}`-style id; auto-generated if absent. */ id?: string; /** * Id of the parent comment when this entry is a reply. Absent for * top-level comments. */ parentId?: string; /** Reference to the author in the workbook persons list. */ personId: string; /** Creation timestamp as an ISO-8601 string. */ date?: string; /** Plain-text body. @mentions are expressed separately via {@link mentions}. */ text: string; /** * Structured `@mention` markers inside `text`. `startIndex`/`length` * point at the substring Excel shows as a clickable mention. */ mentions?: ThreadedCommentMention[]; /** * Whether Excel marks this comment as "resolved". Corresponds to * `done="1"` on the commentExt element. When undefined, Excel treats * the thread as open. */ done?: boolean; } export interface ThreadedCommentMention { mentionId?: string; mentionPersonId: string; startIndex: number; length: number; } /** * Workbook-level person directory referenced by threaded comments. * Written as `xl/persons/person.xml`; one `` element per * unique commenter. */ export interface ThreadedCommentPerson { /** `{GUID}`-style id referenced by `threadedComment/@personId`. */ id: string; /** Display name shown in the UI (e.g. "Jane Doe"). */ displayName: string; /** Provider user id (e.g. "jane@example.com", "S-1-5-…"). */ userId?: string; /** * Identity provider — "AD" (Active Directory), "PeoplePicker", * "None". Excel preserves unknown values verbatim. */ providerId?: string; } export type DataValidationOperator = "between" | "notBetween" | "equal" | "notEqual" | "greaterThan" | "lessThan" | "greaterThanOrEqual" | "lessThanOrEqual"; /** Base properties shared by all data validation types */ interface DataValidationBase { allowBlank?: boolean; error?: string; errorTitle?: string; errorStyle?: string; prompt?: string; promptTitle?: string; showErrorMessage?: boolean; showInputMessage?: boolean; } /** Data validation that requires formulae and operator */ export interface DataValidationWithFormulae extends DataValidationBase { type: "list" | "whole" | "decimal" | "date" | "textLength" | "custom"; formulae: (string | number | Date)[]; operator?: DataValidationOperator; } /** Data validation type 'any' - no formulae needed */ export interface DataValidationAny extends DataValidationBase { type: "any"; } export type DataValidation = DataValidationWithFormulae | DataValidationAny; export interface ImageData { extension: "jpeg" | "png" | "gif"; base64?: string; filename?: string; buffer?: Buffer; /** * Reference the image as an **external link** instead of embedding its bytes. * * When set (and `buffer`/`base64`/`filename` are all omitted), the image is * written as a linked DrawingML picture (``) whose relationship * uses `TargetMode="External"`. No bytes are stored in the `.xlsx` package, so * the file size stays small. The value may be either: * * - an absolute/relative URL (e.g. `"https://example.com/logo.png"`), or * - a local file path (e.g. `"file:///C:/images/logo.png"` or `"images/logo.png"`). * * Note: Excel treats linked images as volatile — a moved/missing target shows a * broken-image placeholder, and modern Excel may not auto-load remote URLs for * security reasons. Use embedding (`buffer`/`base64`) when self-contained files * are required. */ link?: string; /** * Attach a scalable SVG alongside a raster fallback. * * Excel stores SVG pictures as a raster `a:blip` (the `extension`/`buffer`/ * `base64`/`filename` on this object — typically a PNG) plus an * `asvg:svgBlip` extension pointing at the vector data. The raster image is * what older Excel versions and non-SVG consumers render, so it is required; * modern Excel renders the crisp SVG. This library does **not** rasterize — * you supply both the SVG bytes and the raster fallback you want embedded. */ svg?: { /** SVG bytes (mutually use one of buffer/base64/filename). */ buffer?: Buffer; /** Base64-encoded SVG. */ base64?: string; /** Path to an `.svg` file (Node only). */ filename?: string; }; } export interface ImagePosition { tl: { col: number; row: number; }; ext: { width: number; height: number; }; } /** Anchor position for image placement */ export interface ImageAnchor { col: number; row: number; nativeCol?: number; nativeRow?: number; nativeColOff?: number; nativeRowOff?: number; } /** Range input for addImage - can be a string like "A1:B2" or an object */ export type AddImageRange = string | { /** Top-left anchor position */ tl: ImageAnchor | string; /** Bottom-right anchor position (optional if ext is provided) */ br?: ImageAnchor | string; /** Image dimensions (alternative to br) */ ext?: { width: number; height: number; }; /** How the image behaves when cells are resized */ editAs?: "oneCell" | "twoCell" | "absolute"; /** Hyperlink for the image */ hyperlinks?: { hyperlink?: string; tooltip?: string; }; } | { /** Absolute position in pixels — mutually exclusive with tl/br. */ pos: { x: number; y: number; }; /** Image dimensions in pixels (required for absolute positioning). */ ext: { width: number; height: number; }; /** Hyperlink for the image */ hyperlinks?: { hyperlink?: string; tooltip?: string; }; }; export interface ImageHyperlinkValue { hyperlink: string; tooltip?: string; } /** * Preset geometry for a drawing shape. Mirrors the OOXML `prst` vocabulary; * the most common presets are surfaced here, but any valid preset name is * accepted as a fallback `string`. */ export type ShapeType = "rect" | "roundRect" | "ellipse" | "triangle" | "line" | "rightArrow" | "leftArrow" | "upArrow" | "downArrow" | "diamond" | "hexagon" | "star5" | (string & {}); /** Options for `Worksheet.addShape`. */ export interface AddShapeOptions { /** Preset geometry (defaults to `"rect"`). */ type?: ShapeType; /** Where the shape sits — a cell range (e.g. `"B2:D5"`) or anchor object. */ range: AddImageRange; /** Solid fill colour as hex RGB (e.g. `"FF0000"`). Omit for no fill. */ fillColor?: string; /** Outline colour as hex RGB (e.g. `"000000"`). */ lineColor?: string; /** Outline width in points. */ lineWidth?: number; /** Optional centred text label. */ text?: string; /** Display name (defaults to `"Shape N"`). */ name?: string; } /** Internal serialized model for a worksheet shape. */ export interface ShapeModel { type: "shape"; shapeType: string; range: AddImageRange; fillColor?: string; lineColor?: string; lineWidth?: number; text?: string; name?: string; /** * Resolved anchor coordinates, filled in by the worksheet model getter so * the serializer doesn't need range-parsing logic. Mirrors the three image * anchoring modes: two-cell (`tl`+`br`), one-cell (`tl`+`ext`) and absolute * (`pos`+`ext`). Internal only. */ anchorRange?: { tl: { nativeCol: number; nativeColOff: number; nativeRow: number; nativeRowOff: number; }; br?: { nativeCol: number; nativeColOff: number; nativeRow: number; nativeRowOff: number; }; ext?: { width?: number; height?: number; }; pos?: { x: number; y: number; }; editAs?: string; }; } /** * Watermark placement mode in the Excel worksheet. * * - `"overlay"` — Places the watermark image as a DrawingML picture on top of cells. * Visible on screen AND when printed. Supports transparency via ``. * Users can move/delete the watermark unless the sheet is protected. * * - `"header"` — Places the watermark image in the page header using VML. * Renders behind cell content. Visible in Page Layout view and Print Preview. * Cannot be accidentally moved/deleted. The standard "true watermark" approach. */ export type WatermarkMode = "overlay" | "header"; /** * Options for adding a watermark to a worksheet. * * @example Overlay watermark (visible on screen + prints): * ```typescript * const imgId = workbook.addImage({ buffer: pngData, extension: "png" }); * worksheet.addWatermark({ * imageId: imgId, * mode: "overlay", * opacity: 0.15 * }); * ``` * * @example Header watermark (behind content, prints correctly): * ```typescript * const imgId = workbook.addImage({ buffer: pngData, extension: "png" }); * worksheet.addWatermark({ * imageId: imgId, * mode: "header" * }); * ``` */ export interface WatermarkOptions { /** Image ID obtained from `workbook.addImage()`. */ imageId: string | number; /** * Watermark placement mode. * @default "overlay" */ mode?: WatermarkMode; /** * Opacity for overlay mode (0 = fully transparent, 1 = fully opaque). * Expressed as a percentage in OOXML (e.g. 0.15 = 15000 out of 100000). * Only applies to `"overlay"` mode. In `"header"` mode, transparency * must be baked into the image itself (use a PNG with alpha channel). * @default 0.15 */ opacity?: number; /** * Image width in points (for "header" mode VML rendering). * @default 467.25 */ headerWidth?: number; /** * Image height in points (for "header" mode VML rendering). * @default 311.25 */ headerHeight?: number; /** * Which header sections to apply the watermark to (only for "header" mode). * * - `"all"` — applies to oddHeader, evenHeader, and firstHeader * - `"odd"` — applies only to oddHeader (standard pages) * - `"even"` — applies only to evenHeader * - `"first"` — applies only to firstHeader * * @default "all" */ applyTo?: "all" | "odd" | "even" | "first"; } export type Location = { top: number; left: number; bottom: number; right: number; }; export type Address = { sheetName?: string; address: string; col: number; row: number; $col$row?: string; }; export type RowValues = CellValue[] | Record | undefined | null; export type CellIsOperators = "equal" | "greaterThan" | "lessThan" | "between"; export type ContainsTextOperators = "containsText" | "containsBlanks" | "notContainsBlanks" | "containsErrors" | "notContainsErrors"; export type TimePeriodTypes = "lastWeek" | "thisWeek" | "nextWeek" | "yesterday" | "today" | "tomorrow" | "last7Days" | "lastMonth" | "thisMonth" | "nextMonth"; export type IconSetTypes = "5Arrows" | "5ArrowsGray" | "5Boxes" | "5Quarters" | "5Rating" | "4Arrows" | "4ArrowsGray" | "4Rating" | "4RedToBlack" | "4TrafficLights" | "NoIcons" | "3Arrows" | "3ArrowsGray" | "3Flags" | "3Signs" | "3Stars" | "3Symbols" | "3Symbols2" | "3TrafficLights1" | "3TrafficLights2" | "3Triangles"; export type CfvoTypes = "percentile" | "percent" | "num" | "min" | "max" | "formula" | "autoMin" | "autoMax"; export interface Cvfo { type: CfvoTypes; value?: number | string; } export interface ConditionalFormattingBaseRule { priority?: number; style?: Partial