@oniryk/xlsx
Version:
A lightweight, efficient TypeScript library for generating single-sheet Excel XLSX files with support for large datasets
46 lines (45 loc) • 1.57 kB
TypeScript
/**
* Manages shared strings in an Excel workbook
* Handles deduplication and XML generation for the shared strings table
* Used to optimize file size by storing repeated strings only once
*/
export default class SharedStrings {
/** Array of unique strings in the workbook */
private strings;
/** Map of strings to their indices for quick lookup */
private stringIndexMap;
/** Temporary file path for the shared strings XML */
private file;
/**
* Creates a new SharedStrings instance
* Initializes a temporary file for XML generation
*/
constructor();
/**
* Adds a string to the shared strings table
* If the string already exists, returns its index
* If the string is new, adds it and returns the new index
*
* @param str - String to add to the shared strings table
* @returns Index of the string in the shared strings table
*/
add(str: string): number;
/**
* Generates the shared strings XML file
* Creates an XML file containing all unique strings in the workbook
* Processes strings in chunks to manage memory usage
*
* @returns Promise that resolves to the path of the generated XML file
*/
generateSharedStringsXML(): Promise<string>;
/**
* Gets the total number of unique strings in the table
* @returns Number of unique strings
*/
size(): number;
/**
* Clears all strings and mappings from memory
* Should be called when the shared strings table is no longer needed
*/
destroy(): void;
}