import type { Cell } from "../cell.js"; import { Column } from "../column.js"; import { DataValidations } from "../data-validations.js"; import { Dimensions } from "../range.js"; import { Row } from "../row.js"; import type { Medium as WriterMedium } from "./workbook-writer.js"; import { type DrawingAnchor, type DrawingRel } from "../utils/drawing-utils.js"; import type { SharedStrings } from "../utils/shared-strings.js"; import type { StreamBuf } from "../utils/stream-buf.js"; import type { RowBreak, ColBreak, PageSetup, HeaderFooter, WorksheetProperties, WorksheetView, WorksheetState, AutoFilter, WorksheetProtection, ConditionalFormattingOptions, AddImageRange, IgnoredError, WatermarkOptions, RowValues } from "../types.js"; /** * Structural view of the fields/methods WorksheetWriter needs from its * parent WorkbookWriter. Defined here (rather than importing WorkbookWriter * directly) to avoid the circular `workbook-writer.ts <-> worksheet-writer.ts` * dependency. The shape must stay in sync with the concrete WorkbookWriter. */ export interface WorkbookWriterLike { /** Shared-string table (deduplicates plain/rich-text cell values). */ readonly sharedStrings: SharedStrings; /** * Style manager. Typed loosely here (`unknown`) because the concrete * `StylesXform` is an internal xform class and pulling it in would * reintroduce the circular import. Xform methods accept it by duck-typing. */ readonly styles: object; /** Incremented once per dynamic-array formula cell during row commit. */ dynamicArrayCount: number; /** Lookup a media (image/chart) by registered id. */ getImage(id: number): WriterMedium | undefined; /** Open a streaming entry in the output zip for the given path. */ _openStream(path: string): InstanceType; } interface WorksheetWriterOptions { id: number; name?: string; workbook: WorkbookWriterLike; useSharedStrings?: boolean; properties?: Partial; state?: WorksheetState; pageSetup?: Partial; views?: Partial[]; autoFilter?: AutoFilter; headerFooter?: Partial; } /** Internal model for an image added via addImage(). */ interface WriterImageModel { type: "image"; imageId: string; range: { tl: { nativeCol: number; nativeColOff: number; nativeRow: number; nativeRowOff: number; }; br?: { nativeCol: number; nativeColOff: number; nativeRow: number; nativeRowOff: number; }; ext?: { width: number; height: number; }; editAs?: string; /** Absolute position in pixels — mutually exclusive with tl/br cell anchors. */ pos?: { x: number; y: number; }; }; hyperlinks?: { hyperlink?: string; tooltip?: string; }; } declare class WorksheetWriter { id: number; name: string; state: WorksheetState; /** Rows stored while being worked on. Set to null after commit. */ private _rows; /** Column definitions */ private _columns; /** Column keys mapping: key => Column */ private _keys; /** Merged cell ranges */ private _merges; private _sheetRelsWriter; private _sheetCommentsWriter; private _dimensions; private _rowZero; private _rowOffset; committed: boolean; dataValidations: DataValidations; /** Shared formulae by address */ private _formulae; private _siFormulae; conditionalFormatting: ConditionalFormattingOptions[]; ignoredErrors: IgnoredError[]; rowBreaks: RowBreak[]; colBreaks: ColBreak[]; properties: Partial & { defaultRowHeight: number; dyDescent?: number; outlineLevelCol: number; outlineLevelRow: number; }; headerFooter: Partial; pageSetup: Partial & { margins: PageSetup["margins"]; }; useSharedStrings: boolean; private _workbook; hasComments: boolean; private _views; autoFilter: AutoFilter | null; private _media; sheetProtection: { sheet?: boolean; algorithmName?: string; saltValue?: string; spinCount?: number; hashValue?: string; [key: string]: unknown; } | null; private _stream?; startedData: boolean; private _background?; private _headerRowCount?; /** Watermark configuration */ private _watermark; /** Drawing model — populated during commit if images were added */ private _drawing?; /** Relationship Id - assigned by WorkbookWriter */ rId?: string; constructor(options: WorksheetWriterOptions); get workbook(): WorkbookWriterLike; get stream(): InstanceType; destroy(): void; commit(): void; get dimensions(): Dimensions; get views(): Partial[]; get columns(): Column[]; set columns(value: Partial[]); getColumnKey(key: string): Column | undefined; setColumnKey(key: string, value: Column): void; deleteColumnKey(key: string): void; eachColumnKey(f: (column: Column, key: string) => void): void; getColumn(c: string | number): Column; private get _nextRow(); eachRow(options: { includeEmpty?: boolean; } | ((row: Row, rowNumber: number) => void), iteratee?: (row: Row, rowNumber: number) => void): void; private _commitRow; get lastRow(): Row | undefined; findRow(rowNumber: number): Row | undefined; getRow(rowNumber: number): Row; addRow(value: RowValues): Row; addRows(values: RowValues[]): Row[]; findCell(r: string | number, c?: number): Cell | undefined; getCell(r: string | number, c?: number): Cell; mergeCells(...cells: (string | number)[]): void; addConditionalFormatting(cf: ConditionalFormattingOptions): void; removeConditionalFormatting(filter?: number | ((cf: ConditionalFormattingOptions) => boolean)): void; addBackgroundImage(imageId: string | number): void; getBackgroundImageId(): number | undefined; /** * Using the image id from `WorkbookWriter.addImage`, * embed an image within the worksheet to cover a range. */ addImage(imageId: string | number, range: AddImageRange): void; /** * Return the images that have been added to this worksheet. * Each entry contains imageId and the normalised range (with native anchors). */ getImages(): ReadonlyArray; /** * Add a watermark to the worksheet using an image from `WorkbookWriter.addImage()`. * Supports overlay mode (DrawingML with transparency) and header mode (VML behind content). * * `mode: "overlay"` supports external (linked) images; `mode: "header"` does * not — VML header/footer images require embedded media, so a linked image * with `mode: "header"` throws an `ImageError`. * * @throws {ImageError} If `mode: "header"` is used with an external (linked) image. */ addWatermark(options: WatermarkOptions): void; /** * Get the current watermark configuration. */ getWatermark(): WatermarkOptions | null; /** * Remove the watermark from the worksheet. */ removeWatermark(): void; /** * Parse the user-supplied range into a normalised internal model * mirroring what the regular Worksheet / Image class does. */ private _parseImageRange; protect(password?: string, options?: Partial): Promise; unprotect(): void; private _write; private _writeSheetProperties; private _writeSheetFormatProperties; private _writeOpenWorksheet; private _writeColumns; private _writeOpenSheetData; private _writeRow; private _writeCloseSheetData; private _writeMergeCells; private _writeHyperlinks; private _writeConditionalFormatting; /** * Write the `` section at the end of the worksheet. * Currently this only contains conditional formatting extensions (data bar * ext attributes, custom icon sets), but the ExtLstXform will automatically * skip rendering when there is no ext content. * * The prepare phase was already done in _writeConditionalFormatting(). */ private _writeExtLst; private _writeIgnoredErrors; private _writeRowBreaks; private _writeColBreaks; private _writeDataValidations; private _writeSheetProtection; private _writePageMargins; private _writePageSetup; private _writeHeaderFooter; private _writeAutoFilter; private _writeDrawing; /** Returns the drawing model if images were added, for the workbook writer. */ get drawing(): { rId: string; name: string; anchors: DrawingAnchor[]; rels: DrawingRel[]; } | undefined; private _writeBackground; private _writeLegacyData; private _writeDimensions; private _writeCloseWorksheet; } export { WorksheetWriter }; export type { WriterImageModel };