UNPKG

@sheetxl/models

Version:

Models - A Headless javascript spreadsheet library.

1,049 lines (1,048 loc) 37.4 kB
import { RemoveListener, CartesianDirection, Bounds, CellCoords, CellRangeCoords, SetOptions, EditMode } from "@sheetxl/common"; import { TransactionStore, ITransactionStack } from "../transaction"; import { SerializableProperties } from "../primitives"; import { AdjustedColor } from "../color"; import { IListenerSource } from "../listener"; import { CellRangeCoordsAddress, MergeType, ClearType, RangeSortOptions, AutoFillRange, RangeAutoFillOptions, ICellRange, SetCellOptions, CellUpdateValue, CellJSON, CellCoordsAddress, CellAddressValuePair, CoordsValuePair, ModificationVerifier, CellUpdate, CellVisitor, CellVisitorOptions, AutoFitOptions, OverflowedCell, CopyCellsOptions, RangeUpdateValue, IRowHeader, IColumnHeader, RowHeaderJSON, ColumnHeaderJSON, RowHeaderUpdate, ColumnHeaderUpdate, ICellHeader, CellHeaderVisitor, CellHeaderVisitorOptions, ICellModel, ISheetStyle, SheetStyleJSON } from "../cell"; import { IDrawingModel, IDrawingContainer, DrawingAnchorJSON, IDrawingImageModel, AddDrawingImageOptions, DrawingContainerEvent } from "../drawing"; import { ITableModel, TableModelValues, UpdateTableModelOptions } from "../table"; import { ISheetView, ISheetViewListener, CellSelection } from "./ISheetView"; import { ISheetHeadersModel, SetHeaderOptions } from "./ISheetHeadersModel"; import { ISharedResourceCollection, SharedResourceJSON, AddSharedResourceOptions, ISharedResource } from "../resource"; /** @hidden */ export declare const MESSAGE_ERROR_PROTECTION = "This sheet is protected. To make a change, unprotect the sheet. You might be requested to enter a password."; /** @hidden */ export declare const MESSAGE_ERROR_OOB = "The range is outside of the sheet bounds."; /** * Used when the ISheetRange arguments want to be used as a single parameter. The * notable use-case is in the WorkbookConstructor */ export interface ISheetRangeUpdate { /** * The values to update. These can spill outside of the range. * If they are smaller than the range they will be repeated. */ values: RangeUpdateValue; /** * Additional options see @SetCellOptions */ options?: SetCellOptions; } /** * A logically rectangular shape of cells to that can be read * or operated on. */ export interface ISheetRange extends ICellRange { /** * Provides a convenient method for setting values with a range of calls. * @remarks * If an array is passed the values will be in row-major order and will * repeat if the range is larger than the array */ update(values: RangeUpdateValue, options?: SetCellOptions): void; /** * @see {@link ISheetModel.sort} */ sort(options?: RangeSortOptions): void; /** * @see {@link ISheetModel.clear} */ clear(clearType?: ClearType): CellRangeCoords | null; /** * @see {@link ISheetModel.merge} */ merge(mergeType?: MergeType): CellRangeCoords | null; /** * @see {@link ISheetModel.unmerge} */ unmerge(): CellRangeCoords | null; /** * @see {@link ISheetModel.insertCells} */ insertCells(direction?: CartesianDirection.Down | CartesianDirection.Right, options?: SetOptions): void; /** * @see {@link ISheetModel.removeCells} */ removeCells(direction?: CartesianDirection.Up | CartesianDirection.Left, options?: SetOptions): void; /** * @see {@link ISheetModel.hideRows} */ hideRows(options?: SetOptions): void; /** * @see {@link ISheetModel.hideColumns} */ hideColumns(options?: SetOptions): void; /** * @see {@link ISheetModel.unhideRows} */ unhideRows(options?: SetOptions): void; /** * @see {@link ISheetModel.unhideColumns} */ unhideColumns(options?: SetOptions): void; /** * @see {@link ISheetModel.autoFitRows} */ autoFitRows(options?: AutoFitOptions): void; /** * @see {@link ISheetModel.autoFitColumns} */ autoFitColumns(options?: AutoFitOptions): void; /** * @see {@link ISheetModel.autoFitColumns} */ autoFit(options?: AutoFitOptions): void; /** * Copy current range to a new location * @See {@link ISheetModel.copyCells} */ copyTo(range: ISheetRange, options?: CopyCellsOptions): void; /** * Provides a convenient method for setting values with a range of calls. * @see {@link ISheetHeadersModel.update} * @remarks * If an array is passed the values will be in row-major order and will * repeat if the range is larger than the array */ updateColumns(values: ICellHeader | ColumnHeaderUpdate | null, options?: SetHeaderOptions): void; /** * Provides a convenient method for updating rows. * @see {@link ISheetHeadersModel.update} * @remarks * If an array is passed the values will be in row-major order and will * repeat if the range is larger than the array */ updateRows(values: ICellHeader | RowHeaderUpdate | null, options?: SetHeaderOptions): void; /** * If the range is readonly only. */ isReadOnly(): boolean; /** * Return the ISheetModel */ sheet(): ISheetModel; /** * For runtime type identification. */ readonly isSheetRange: true; } export interface SheetRangeEvent { /** * The source of the event */ getSheet(): ISheetModel; /** * The range that the event is for. */ getRange(): ISheetRange; /** * The type of event. */ readonly trigger: string; } /** * A callback for when a range or sheet has been modified * @remarks * A range can be invalid if the rows/columns or sheet have been deleted */ export type ISheetRangeListener = (event: SheetRangeEvent) => void; /** * Range listeners are used to listen to changes to a range. */ export interface RangeListenerOptions { /** * Ignore cell updates. This will fire events if the range has * shifted but will not fire events for cells updates * @defaultValue false */ ignoreCellUpdates?: boolean; ignoreStyleUpdates?: boolean; /** * The actual range can also change due to insert/removes or delete of a sheet. * Setting absoluteCoords to true will ignore shifts in the range. * @defaultValue false */ absolute?: boolean; /** * Range listeners are always part of the transaction stack. * This means that the range listener will not be called on undo events before * it was added. * The within transaction flag will allow the listener to be called on all incremental changes. * * This is useful for operations that want to write with the same transaction. * This has several implications. * 1. The listener will be fired for all incremental changes during the transaction. * 2. The range operators can be written too. * 3. Listeners will not be fired on undo as these are handled by transaction state. * * @remarks * @defaultValue false */ withinTransaction?: boolean; /** * If true then the listener will be weakly held. * @defaultValue false */ weakly?: boolean; /** * Used for undo notification. If provided this will also fire a range event on add. */ fromEvent?: SheetRangeEvent; } /** * Sheets may contain complex objects such as tables, drawings, images, listeners or other items. * These can be copied from one sheet to another via a callback. */ export interface CopyableSheetItem { /** * Called when the item is copied to a new sheet. * // TODO - generalize the drawing */ copyToSheet(sheet: ISheetModel, range: CellRangeCoords, options?: CopyCellsOptions): void; /** * Called on paste */ onPaste?(sheet: ISheetModel, sheetView: ISheetView): Promise<void> | void; /** * For runtime introspection. */ readonly isCopyableSheetItem: true; /** * The range that bounds the current item. */ range?(): CellRangeCoords; /** * Allow items to be copied as text. */ toText?(): string; /** * Allow items to be copied as html. */ toHtml?(): string; /** * Allow items to be copied as an image Blob. */ toImage?(): Promise<Blob> | Blob; } /** * Useful for when we are not copying from the current sheet. * This abstraction exists to allow for custom sources such as a clipboard. * * @remarks * There is a default implementation CopySheetSource that can be used * to copy between sheets. */ export interface CopySheetSource { /** * The name of a the copy source. Useful for user interactions. * @remarks * CopySheetSource uses the sheet name to detect intersections. */ name?(): string; /** * The source range */ rangeFrom(): CellRangeCoords; /** * Scan the values of the source range * @param visitor * @param options */ scanCells(visitor: CellVisitor, options?: CellVisitorOptions): void; /** * Scan any rows. * @param visitor * @param options */ scanRowHeaders?(visitor: CellHeaderVisitor, options?: CellHeaderVisitorOptions): void; /** * Scan any columns. * @param visitor * @param options */ scanColHeaders?(visitor: CellHeaderVisitor, options?: CellHeaderVisitorOptions): void; /** * Return copyable items that are not cells. * @remarks */ getCopyableItems?(): CopyableSheetItem[]; /** * Flag to indicate if the operation is expected to be a cut. * @defaultValue false */ isCut?(): boolean; /** * This is called when the copy has read the source * If copy should not be allowed (for example a read only sheet) then return false */ onCopy?(): boolean; /** * Notify when the paste operation is complete. */ onPaste?(): Promise<boolean> | boolean; /** * Notify when the paste operation is cancelled. */ onCancel?(): void; /** * EditMode */ editMode?(): EditMode; /** * For runtime introspection. */ readonly isCopySheetSource: true; } export interface ModifyTableSetOptions extends UpdateTableModelOptions { clearFormatting?: boolean; } /** * If the SheetProtection is present then everything is readonly. * Setting any of the attributes allows these types of changes to be done. */ export interface SheetProtection { autoFilter: boolean; deleteColumns: boolean; deleteRows: boolean; formatCells: boolean; formatColumns: boolean; formatRows: boolean; insertColumns: boolean; insertHyperlinks: boolean; insertRows: boolean; objects: boolean; pivotTables: boolean; scenarios: boolean; selectLockedCells: boolean; selectUnlockedCells: boolean; sheet: boolean; sort: boolean; /** * If this is specified then a password will be requested to unlock */ verifier: ModificationVerifier; } export interface RangeProtection { /** * Must be unique across all RangeProtections but is not related to the sheet range */ name: string; /** * The range that is protected */ range: CellRangeCoords; /** * If this is specified then a password will be requested to unlock */ verifier?: ModificationVerifier; } export interface SheetModelEvent extends DrawingContainerEvent<ISheetModel> { } export declare enum SheetModelListenerType { /** * The tab color. */ TabColor = "tabColor", /** * Convenience method that listens to all changes on the style. */ Style = "style", /** * If any cell changes * @remarks * For specific changes use addRangeListener */ Cells = "cells", /** * If any merge changes */ Merges = "merges", /** * If the drawing collections changes. * @remarks * This does not notify of the individual drawing changes themselves. For this listen directly to the drawing. */ Drawings = "drawings", /** * If the row/column sizes have changed */ Layout = "layout", /** * If any protection changes */ Protection = "protection", /** * Called when delete is called. */ Delete = "delete", /** * Called when the sheet is closed */ Close = "close" } export interface ISheetModelListener extends ISheetViewListener { /** * Called when the sheet tab color changes */ onTabColorChange?(): void; /** * Convenience method that listens to all changes on the style. */ onStyleChange?(): void; /** * Called when a long running operation is started. This is useful to * give the user feedback that the operation is still running. * @remarks * This must return a function or a promise to a function that can be called when the operation is complete * This will not always be called as some operations may determine that they would be to 'quick'. * @param operationName */ onOperation?: (operationName: string) => (Promise<() => void>) | (() => void); /** * If any cell changes * @remarks * For specific changes use addRangeListener */ onCellsChange?(): void; /** * If any merge changes */ onMergesChange?(): void; /** * If any drawing changes */ onDrawingsChange?(): void; /** * If the row/column sizes have changed */ onLayoutChange?(): void; /** * If any protection changes */ onProtectionChange?(): void; /** * Called when delete is called. */ onDelete?(model: ISheetModel): void; /** * Called when the sheet is closed */ onClose?(): void; } /** * Options for the replace operation. */ export interface ReplaceCellOptions extends SetCellOptions { findOptions: FindCellOptions; isReplaceAll?: boolean; onReplaceText?: (coord: CellCoords, text: string) => void; } export declare enum FindCellField { Formula = "formula", Value = "value", Comment = "comment", Note = "note" } /** * Options for the find operation */ export interface FindCellOptions { /** * If the search is case sensitive * @defaultValue false */ isMatchCase?: boolean; isMatchEntireCell?: boolean; isUseRegex?: boolean; /** * Search in reverse order * @defaultValue false */ isReverse?: boolean; isRowScan?: boolean; /** * The cell to start from * @defaultValue. The next cell after the current selection */ from?: CellCoordsAddress; /** * The cell to end at */ to?: CellCoordsAddress; /** * Checks the from cell for a match * @defaultValue false */ includeFrom?: boolean; /** * Determine if will wrap back to beginning * @defaultValue false */ disableWrap?: boolean; fields?: FindCellField[]; /** * A bounds to limit the find by. * @defaultValue 'This will use the current range bounds if there is a single bounds. Otherwise it will use the entire sheet' */ bounds?: CellRangeCoordsAddress; /** * Called on a found results. * @remarks * This will break unless an explicit false is returned. * */ onFound?: (pair: CoordsValuePair<ICellModel>) => boolean | void; } export declare enum CountCellItemType { Content = "content", Style = "style", Formula = "formula", Comments = "comments", Error = "error", Warnings = "errors" } /** * Goto to the location. * * @remarks * If the updateSelection is false it will only update the selection * if the current location is not currently in the selection range. * If preserverAnchor is false the anchor will always reset to the top left. * * @param location * @param updateSelection Update the selection. @defaultValue true * @param preserveAnchor Keep the anchor in current location. @defaultValue true */ export interface GotoOptions { /** * The range to goto. */ range?: ISheetRange | string; /** * If specified then will also attempt to focus the drawing. */ drawing?: IDrawingModel; /** * If true goto will update the selection. * @defaultValue true */ updateSelection?: boolean; /** * If true goto will attempt to preserve the anchor. * @defaultValue true */ preserveAnchor?: boolean; } /** * Interface used to access the SheetModel API. * When interactive the cells it is advisable to use {@link ISheetRange} * that is returned from the {@link getRange} method. * @see {@link getRange} @see {@link ISheetRange} */ export interface ISheetModel extends ITransactionStack, IDrawingContainer<ISheetModel>, IListenerSource<SheetModelEvent> { /** * Returns an immutable cell from the specified address. * This can be either a CellCoord or a case insensitive 'a1' style string reference. * If no address is specified then the current selection is used. * * @remarks * Will never return null. * * @param address either a coord or an a1 string */ getCell(address?: CellCoordsAddress): ICellModel; /** * Set a single value. This is a convenience method that wraps setCellPairs * to provide a simpler interface. For higher performance use @see {@link setCellPairs} directly. * * @remarks * This operation also runs synchronously. */ setCell(address: CellCoordsAddress, value: CellUpdateValue, options?: SetCellOptions): ICellModel; /** * Returns a range of cells for the specified range. * These allow for interaction with the cells. * If no address is specified then this will use the intersection of the cell * bounds and the selection bounds. * @see {@link ISheetRange} */ getRange(address?: CellRangeCoordsAddress): ISheetRange; /** * Sets a collection of Cells in a single batch/transaction. * * This allows for an array of different values to be set as a single update. * This is useful for non-contiguous updates and greatly improves performance * over setting individually. * * @see {@link CellAddressValuePair} * @param pairs */ setCellPairs(pairs: CellAddressValuePair[], options?: SetCellOptions): void; /** * Returns the active address as an A1 style reference */ getActiveAddressCoordsA1(): string; /** * Return the active address as a cell coord */ getActiveAddressCoords(): CellCoords; /** * Returns a single value for the found result or null if not found. * @param options */ find(findText: string, options?: FindCellOptions): CoordsValuePair<ICellModel> | null; /** * Returns an array of merges that intersect the range coordinates. */ getMerges(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[]): CellRangeCoords[]; /** * Merges all cells within the selection ranges. * If the ranges overlap then this operation will throw an exception * * @param addresses list of ranges @defaultValue to current selection * @param mergeType @defaultValue MergeType.All * @returns the intersection of all ranges applied */ merge(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], mergeType?: MergeType): CellRangeCoords | null; /** * UnMerges all cells within the selection ranges. * If the ranges don't contain merges or the ranges overlap then this operation will throw an exception. * @param addresses list of ranges @defaultValue to the current selection * @returns the intersection of all ranges applied */ unmerge(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[]): CellRangeCoords | null; /** * Returns an array of Tables are in the range. * @remarks * If no arguments are provided then this will return all tables in the Sheet. */ getTables(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], includeHidden?: boolean): ITableModel[]; /** * Create a table at the given range. If the range is already a table then it will be updated. * @remarks * * If no update is passed in then a default table will be create. * If a ref is not specified then the range will be used as the ref. * If a ref is specified then the rowStart of ref must match the range or an error will occur. */ upsertTable(address: CellRangeCoordsAddress, update?: SerializableProperties<TableModelValues>, options?: ModifyTableSetOptions): ITableModel; /** * Remove any tables within the range. * * @param address */ removeTables(address?: CellRangeCoordsAddress | CellRangeCoordsAddress[], options?: ModifyTableSetOptions): number; /** * Add an image to the current sheet. * This will return an IDrawingImageModel that can be used to manipulate the image or remove it. * * @param image This can be either string to a url, a SharedResource or an AddSharedResourceOptions * @param options AddDrawingImageOptions */ addImage(image: string | ISharedResource | AddSharedResourceOptions, options?: AddDrawingImageOptions): Promise<IDrawingImageModel>; /** * Hides the rows for the given ranges. * If no range is provided the the current selection is used * @param addresses */ hideRows(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], options?: SetOptions): void; /** * Hides the columns for the given ranges. * If no range is provided the the current selection is used * @param addresses */ hideColumns(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], options?: SetOptions): void; /** * Unhides the rows for the given ranges. * If no range is provided the the current selection is used * @param addresses */ unhideRows(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], options?: SetOptions): void; /** * Unhides the columns for the given ranges. * If no range is provided the the current selection is used * @param addresses */ unhideColumns(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], options?: SetOptions): void; /** * Adjust the row height to fit the content. If empty then will use the normal style height. * @param addresses * @param options */ autoFitRows(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], options?: AutoFitOptions): void; /** * Adjust the columns width to fit the content. If empty then will use an algo to fit 8.43 characters. * * @see {@link https://docs.microsoft.com/en-us/office/troubleshoot/excel/determine-column-widths} * @param addresses * @param options */ autoFitColumns(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], options?: AutoFitOptions): void; /** *Adjusts both the column widths and rows heights to fit the content. */ autoFit(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], options?: AutoFitOptions): void; /** * Sort the given range. * @remarks * The sorting of various data types has a default priority of of boolean > string > number and dates are treated as numbers. * * @param address * @param options @see {@link RangeAutoFillOptions} */ sort(address?: CellRangeCoordsAddress, options?: RangeSortOptions): void; /** * Given the range extend the cells in a certain direction. * * Note - If the range contains merges then the amount must be a 'fill' dimension must a multiple of the initialRange 'fill' dimension. * * @param ranges @see {@link AutoFillRange} * @param direction the direction to fill @see {@link CartesianDirection} * @param options @see {@link RangeAutoFillOptions} * * @return Returns a function that provides the ability to see a setter for a given autofill offset. * If this is negative then it will return a setter in the opposite of the direction */ autoFill(ranges: AutoFillRange[], direction: CartesianDirection, options?: RangeAutoFillOptions): (offset: number) => CellAddressValuePair; /** * Will copy cells into the range from the source ranges or from the CopyCellSource * * @param destination * @param source * @param options */ copyCells(destination: CellRangeCoordsAddress | CellRangeCoordsAddress[], source: CellRangeCoordsAddress | CellRangeCoordsAddress[] | CopySheetSource, options?: CopyCellsOptions): void; /** * insert cells at the range. * By default the values will direction in whichever direction the selection shape is smaller. * For example a selection with a 5 column by 1 row will direction Down (rows). * Note - This will error if direction data will fall outsize of the max sheet size * * @param addresses A string or CellRangeCoords or an array of either. * @param direction @defaultValue 'based on the selection shape' */ insertCells(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], direction?: CartesianDirection.Down | CartesianDirection.Right, options?: SetOptions): void; /** * Remove cells at a range. * This is different than clearing cells in that it direction value up or left. * @param addresses A string or CellRangeCoords or an array of either. * @param direction @defaultValue 'based on the selection shape' */ removeCells(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], direction?: CartesianDirection.Up | CartesianDirection.Left, options?: SetOptions): void; /** * Clear the cells. * * @param addresses A string or CellRangeCoords or an array of either. * @param clearType @defaultValue ClearType.Content */ clear(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], clearType?: ClearType): CellRangeCoords | null; /** * Returns all overflowed cells with the given range. If a null range is provided then all overflowed calls will be returned. * @param address A string or CellRangeCoords. * @param includeHidden defaults to false. If overflowed should also return hidden. * TODO - This needs to be moved to view since it's dependant on scale */ getOverflows(address?: CellRangeCoordsAddress, includeHidden?: boolean): OverflowedCell[]; /** * Returns the row headers managed by the Sheet. */ getRowHeaders(): ISheetHeadersModel<IRowHeader, RowHeaderJSON, RowHeaderUpdate>; /** * Returns the column headers managed by the Sheet. */ getColumnHeaders(): ISheetHeadersModel<IColumnHeader, ColumnHeaderJSON, ColumnHeaderUpdate>; /** * Defaults to null means that there is no customized color * @defaultValue null */ getTabColor(): AdjustedColor; /** * See the tab color for the sheet. * @remarks * The tab color is not used by the sheet but rather by the workbook. * @param color The color */ setTabColor(color: AdjustedColor | string): void; /** * If null then there is no protection * @defaultValue null */ getProtection(): Readonly<SheetProtection> | null; /** * Set the protection. This will merge with existing protection. * * @remarks Pass null to clear all protections. * @param protection */ setProtection(protection: Partial<SheetProtection> | null): void; /** * Returns an array of ProtectedRanges. */ getProtectedRanges(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[]): RangeProtection[]; /** * Protect a set of ranges. * * @param addresses list of ranges @defaultValue to current selection * @param rangeProtection @defaultValue Simple protection * @returns the intersection of all ranges applied */ protectRanges(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], rangeProtection?: RangeProtection): CellRangeCoords | null; /** * Unprotected all cells within the selection ranges. * @param addresses list of ranges @defaultValue to the current selection * @returns the intersection of all ranges applied */ unprotectRanges(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], password?: string): CellRangeCoords | null; /** * The view specific properties. */ getView(): ISheetView; /** * Set the view specific properties. This will merge with existing view. * * @param view This can not be mull */ setView(view: Partial<ISheetView>): void; /** * Returns the sheetStyle associated with the sheet. */ sheetStyle(): ISheetStyle; /** * Returns the current shared resources. */ sharedResources(): ISharedResourceCollection; /** * Returns the minimum bounds that includes all cell data. * @remarks * This is guaranteed to always return at least a single cell. * This will returns cells that have either styling or a value. * * @param includeHeaders include custom headers in sizing. @defaultValue false * @param includeHidden include cells in hidden headers. @defaultValue false */ getCellBounds(includeHeaders?: boolean, includeHidden?: boolean): CellRangeCoords; /** * Returns the minimum bounds that includes all cells selections. */ getSelectionBounds?(): CellRangeCoords; /** * The maximum cell bounds. */ getMaxCellRange?(): CellRangeCoords; /** * Returns the next coord in a given direction that has a value within the sheet. * @remarks * This will skip cells with styling but no value. */ findNextBoundary(currentCoords: CellCoords, direction: CartesianDirection, first?: boolean, limit?: number): number; /** * Returns a CellRangeCoords that represents the 'closest' contentful data */ findRegionBounds(selection?: CellSelection, expandIfSelected?: boolean, alwaysSelectAll?: boolean): CellRangeCoords; /** * Returns a list of items that can be copied to another sheet or to the clipboard. * If null then nothing is returned. * @param ranges */ getCopyableItems(ranges: CellRangeCoords[]): CopyableSheetItem[]; /** * Returns a list of items for the given types. If no options is provided then it will return * counts for the select range. If there given address is empty then this will return null. * @param address * @param types * * The types will be used to filter the results. * If a number is provided this will be a max number * If a boolean is provided this will be a statement to include/exclude * @remarks * Some uses cases for this are checking for data to delete a sheet, checking for multiple values * for merges, or displaying stats. */ countItems(address?: CellCoordsAddress | CellRangeCoordsAddress, types?: Partial<Record<CountCellItemType, number | boolean>>): Record<CountCellItemType, number> | null; /** * Determine if dates should be 1904 instead of 1900 based */ is1904DateSystem(): boolean; /** * Returns the column width as a font unit. This is used as * an informative tooltip * @param pixelWidth */ getColumnWidthAsFontUnit(pixelWidth: number): number; /** * Returns the absolute bounds of a given address. * @param address */ getBoundsFromRange(address: CellCoordsAddress | CellRangeCoordsAddress): Bounds; /** * Returns the ranges for a given bounds * @param bounds */ getRangeFromBounds(bounds: Bounds): CellRangeCoords; /** * Creates a cell that is not including at a coordinate but adopts all rendering. * Useful for previewing values such as tooltip. If the coords are passed it will return * a disconnect cell update for that value. * * @remarks * * This does not add to the sheet but provides a standalone ICellModel. * * @param update * @param coords * @returns a detached ICellModel */ createCellTemplate(update: CellUpdate | ICellModel | null, coords?: CellCoords): ICellModel | null; /** * Return the empty Cell. useful for quick comparisons. */ emptyCell(): ICellModel; /** * All for listen to changes to the sheet. To remove listener call the returned function. * @param listener * @returns An unsubscribe function */ addListener: (listener: ISheetModelListener) => RemoveListener; /** * Add a listener for a specific range. * * @remarks * By default insert/remove of headers will alter the range listener. To see the actually bounds * use the range in the callback. * * @param address * @param listener @see {@link ISheetRangeListener} * @param options @see {@link RangeListenerOptions} * * If the sheet is cleared this will auto remove the listener. */ addRangeListener(address: CellRangeCoordsAddress, listener: ISheetRangeListener, options?: RangeListenerOptions): RemoveListener; /** * A display name for the sheet. * @remarks * This is readonly from the sheet and is set via the container, usually an IWorkbook. */ getName(): string; /** * This removes from a container if one is in use. */ delete(): void; /** * Returns a JSON representation of the sheet. * This can be used with @see {@link fromJSON} to reload or passed * into the constructor. */ toJSON(): Promise<SheetJSON>; /** * Load the @see {@link SheetJSON} state into memory. The current state will be lost. * @param json */ fromJSON(json: SheetJSON): void; /** * Free all resources associated with the sheet and mark as read-only. * @remarks * This is called by workbooks when the workbook is is closed. * This is different than delete which removes the sheet from the workbook. * @see {@link ISheetModel.addListener} for closeEvent */ close(): void; /** * Returns true if the sheet has been closed. */ isClosed(): boolean; /** * Used for runtime reflection. */ readonly isISheetModel: true; } /** * CellsJSON supports basic types too. An empty value is a stub */ export type CellsJSON = Record<string, CellsJSONValue>; export type CellsJSONValue = CellJSON | {} | string | number; export interface CellsRow { r: number; c?: CellsJSON; } export interface SheetJSON { data?: CellsRow[] | undefined; cols?: ColumnHeaderJSON[]; rows?: RowHeaderJSON[]; style?: SheetStyleJSON; resources?: SharedResourceJSON[]; merged?: string[]; tables?: SerializableProperties<TableModelValues>[]; drawings?: DrawingAnchorJSON[]; tabColor?: SerializableProperties<AdjustedColor>; protection?: SerializableProperties<SheetProtection>; protectedRanges?: SerializableProperties<RangeProtection>[]; view?: SerializableProperties<ISheetView>; comments?: any; threadedComments?: any; } export interface CellSelectionJSON { activeCoords?: string; activeRangeIndex?: number; ranges?: string[]; } export interface ICellContainerOptions { /*** * Set the maxRow size * @defaultValue 1048576 */ maxRows?: number; /*** * Set the maxRow size * @defaultValue 16384 */ maxColumns?: number; /** * collection of shared styles. * If not provided then workbook will create it's own. */ sheetStyle?: ISheetStyle; /** * collection of shared resources. * If not provided then workbook will create it's own. */ sharedResources?: ISharedResourceCollection; /** * Determine if dates should be 1904 instead of 1900 based * @defaultValue false */ isDate1904System?: boolean; /** * The store for all state changes. This is provided to enable versioning, undo/redo, distributed editing, etc. * @defaultValue internal */ transactionStore?: TransactionStore; } /** * Optional values passed to a sheet */ export interface ISheetModelOptions extends ICellContainerOptions { /** * A unique identifier used for identifying this sheet during operations (i.e. copy/paste). * This must be unique for all in-memory instances of a sheet. * * Note - it is not saved as part of the persisted model @see {@link SheetJSON}. * @param uid - unique identifier for in memory operations. If not provided a default one will be used. */ uid?: string; /** * Callback to provide a sheet with a logical name. This is used * when a sheet name property is invoked. * @remarks * Sheets don't have a name by default but as a convenience we allow * for the name to be called on a sheet */ getName?: (model: ISheetModel) => string | null; /** * Callback for delete before the sheet is deleted. If this throws an error then * the delete will be aborted. * * @param model */ onBeforeDelete?: (model: ISheetModel) => void; } //# sourceMappingURL=ISheetModel.d.ts.map