@oniryk/xlsx
v0.0.4
Published
A lightweight, efficient TypeScript library for generating single-sheet Excel XLSX files with support for large datasets
Maintainers
Readme
@oniryk/xlsx
A lightweight, efficient TypeScript library for generating single-sheet Excel XLSX files with support for large datasets
Features
- Optimized for large datasets
- Support for dates, numbers, and text content
- Custom column widths
- TypeScript types included
Installation
npm install @oniryk/xlsxQuick Start
import { SharedStrings, Sheet, build } from '@oniryk/xlsx';
// Create instances for string management and worksheet
const strings = new SharedStrings();
const sheet = new Sheet(strings);
// Add headers
sheet.addRow(['Name', 'Age', 'Date']);
// Add data
sheet.addRow(['John Doe', 25, new Date('2024-01-31')]);
sheet.addRow(['Jane Smith', 30, new Date('2024-02-15')]);
// Generate the Excel file
const buffer = await build(sheet, strings);
// Save to file or send as response
await fs.writeFile('output.xlsx', buffer);API Reference
SharedStrings
Manages string deduplication across the workbook:
const strings = new SharedStrings();Methods:
add(str: string): number- Adds a string to the shared strings tablesize(): number- Gets the total number of unique stringsdestroy(): void- Cleans up resources
Sheet
Handles worksheet data and formatting:
const sheet = new Sheet(sharedStrings);Methods:
addRow(row: Row): void- Adds a single rowaddRows(rows: Row[]): void- Adds multiple rowsrowsCount(): number- Gets total row countsetColumWidth(index: number, width: number): void- Sets width for a single columnsetColumWidth(sizes: [number, number][]): void- Sets widths for multiple columns
Types
type Cell = string | number | Date | null;
type Row = Cell[];Column Width Configuration
You can customize column widths either individually or in bulk:
// Set single column width
sheet.setColumWidth(0, 15); // Set column A to width 15
// Set multiple column widths
sheet.setColumWidth([
[0, 15], // Column A: width 15
[1, 20], // Column B: width 20
[2, 10] // Column C: width 10
]);Date Handling
Dates are automatically converted to Excel's internal format and styled appropriately:
sheet.addRow(['Date', new Date('2024-01-31')]);Limitations
Current version limitations:
- Single Sheet Only: The library currently only supports generating Excel files with a single worksheet. Multi-sheet support is planned for future releases.
- Basic Styling: Only basic cell formatting is supported (dates and numbers). Advanced styling features like colors, borders, and fonts are not yet implemented.
Contributing
Contributions are welcome! Please ensure:
- TypeScript types are maintained
- Documentation is updated
- Code follows the existing style
License
Distributed under the ISC License. See LICENSE for more information.
This documentation was generated using AI tools. Please report any inaccuracies through GitHub issues.
