UNPKG

@mertdeveci55/univer-import-export

Version:

Excel/CSV import and export library for Univer spreadsheets with full format preservation

165 lines (164 loc) 5.1 kB
/** * Utility functions for Excel Export * * This file contains shared utility functions to avoid code duplication * and ensure consistent behavior across the export functionality. */ /** * Convert a 0-based column number to Excel column letter(s) * Examples: 0 -> 'A', 1 -> 'B', 25 -> 'Z', 26 -> 'AA', 27 -> 'AB' * * @param colNumber - 0-based column index * @returns Excel column letter(s) * @throws Error if column number is negative or exceeds Excel's maximum */ export declare function columnNumberToLetter(colNumber: number): string; /** * Convert Excel column letter(s) to 0-based column number * Examples: 'A' -> 0, 'B' -> 1, 'Z' -> 25, 'AA' -> 26, 'AB' -> 27 * * @param columnLetter - Excel column letter(s) * @returns 0-based column index * @throws Error if column letter is invalid */ export declare function columnLetterToNumber(columnLetter: string): number; /** * Convert 0-based row/column indices to 1-based for Excel * * @param zeroBasedIndex - 0-based index * @returns 1-based index for Excel */ export declare function toOneBased(zeroBasedIndex: number): number; /** * Convert 1-based Excel indices to 0-based * * @param oneBasedIndex - 1-based Excel index * @returns 0-based index */ export declare function toZeroBased(oneBasedIndex: number): number; /** * Create an Excel cell reference from row and column indices * * @param row - 0-based row index * @param col - 0-based column index * @param absolute - Whether to use absolute references ($) * @returns Excel cell reference (e.g., 'A1', '$A$1') */ export declare function createCellReference(row: number, col: number, absolute?: { row?: boolean; col?: boolean; }): string; /** * Create an Excel range reference from start and end coordinates * * @param startRow - 0-based start row * @param startCol - 0-based start column * @param endRow - 0-based end row * @param endCol - 0-based end column * @returns Excel range reference (e.g., 'A1:C3') */ export declare function createRangeReference(startRow: number, startCol: number, endRow: number, endCol: number): string; /** * Parse an Excel cell reference to get row and column indices * * @param cellRef - Excel cell reference (e.g., 'A1', '$B$2') * @returns Object with 0-based row and column indices and absolute flags */ export declare function parseCellReference(cellRef: string): { row: number; col: number; absoluteRow: boolean; absoluteCol: boolean; } | null; /** * Parse an Excel range reference to get start and end coordinates * * @param rangeRef - Excel range reference (e.g., 'A1:C3') * @returns Object with start and end coordinates (0-based) */ export declare function parseRangeReference(rangeRef: string): { startRow: number; startCol: number; endRow: number; endCol: number; } | null; /** * Validate if a value represents a boolean in Excel terms * * @param value - Value to check * @returns Boolean representation or undefined if not boolean */ export declare function toBooleanValue(value: any): boolean | undefined; /** * Check if a row index is valid for Excel * * @param row - 0-based row index * @returns True if valid */ export declare function isValidRow(row: number): boolean; /** * Check if a column index is valid for Excel * * @param col - 0-based column index * @returns True if valid */ export declare function isValidColumn(col: number): boolean; /** * Check if a cell reference is valid * * @param row - 0-based row index * @param col - 0-based column index * @returns True if valid cell reference */ export declare function isValidCell(row: number, col: number): boolean; /** * Safely get a value from a nested object structure * * @param obj - Object to get value from * @param path - Path to the value (e.g., 'a.b.c') * @param defaultValue - Default value if path doesn't exist * @returns Value at path or default */ export declare function safeGet<T = any>(obj: any, path: string, defaultValue?: T): T; /** * Create a unique identifier for a range * * @param startRow - Start row (0-based) * @param startCol - Start column (0-based) * @param endRow - End row (0-based) * @param endCol - End column (0-based) * @returns Unique range identifier */ export declare function createRangeId(startRow: number, startCol: number, endRow: number, endCol: number): string; /** * Normalize a sheet name for comparison * * @param name - Sheet name * @returns Normalized sheet name */ export declare function normalizeSheetName(name: string): string; /** * Check if two ranges overlap * * @param range1 - First range * @param range2 - Second range * @returns True if ranges overlap */ export declare function doRangesOverlap(range1: { startRow: number; startCol: number; endRow: number; endCol: number; }, range2: { startRow: number; startCol: number; endRow: number; endCol: number; }): boolean; /** * Deep clone an object (simple implementation for plain objects) * * @param obj - Object to clone * @returns Cloned object */ export declare function deepClone<T>(obj: T): T;