npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

han-excel-builder

v1.0.5

Published

Advanced Excel file generator with TypeScript support, comprehensive styling, and optimized performance

Readme

Han Excel Builder

🚀 Advanced Excel file generator with TypeScript support, comprehensive styling, and optimized performance

A modern, fully-typed library for creating complex Excel reports with multiple worksheets, advanced styling, and high performance.

✨ Features

  • 📊 Multiple Worksheets Support - Create complex workbooks with multiple sheets
  • 🎨 Advanced Styling - Full control over fonts, colors, borders, and cell formatting
  • 📈 Data Types - Support for strings, numbers, dates, percentages, and custom formats
  • 🔧 TypeScript First - Complete type safety with comprehensive interfaces
  • High Performance - Optimized for large datasets with streaming support
  • 🧪 Fully Tested - Comprehensive test suite with 100% coverage
  • 📚 Well Documented - Complete API documentation with examples
  • 🛠️ Developer Friendly - ESLint, Prettier, and modern tooling

📦 Installation

npm install han-excel-builder
# or
yarn add han-excel-builder
# or
pnpm add han-excel-builder

🚀 Quick Start

import { ExcelBuilder, CellType, NumberFormat, StyleBuilder } from 'han-excel-builder';

// Create a simple report
const builder = new ExcelBuilder();

const worksheet = builder.addWorksheet('Sales Report');

// Add headers
worksheet.addHeader({
  key: 'title',
  value: 'Monthly Sales Report',
  type: CellType.STRING,
  mergeCell: true,
  styles: StyleBuilder.create()
    .fontBold()
    .fontSize(16)
    .centerAlign()
    .build()
});

// Add sub-headers
worksheet.addSubHeaders([
  {
    key: 'product',
    value: 'Product',
    type: CellType.STRING,
    width: 20
  },
  {
    key: 'sales',
    value: 'Sales',
    type: CellType.NUMBER,
    width: 15,
    numberFormat: NumberFormat.CURRENCY
  }
]);

// Add data
worksheet.addRow([
  { key: 'product', value: 'Product A', type: CellType.STRING },
  { key: 'sales', value: 1500.50, type: CellType.NUMBER }
]);

// Generate and download
await builder.generateAndDownload('sales-report');

📚 API Documentation

Core Classes

ExcelBuilder

Main class for creating Excel workbooks.

const builder = new ExcelBuilder({
  author: 'Your Name',
  company: 'Your Company',
  created: new Date()
});

Worksheet

Represents a single worksheet in the workbook.

const worksheet = builder.addWorksheet('Sheet Name', {
  tabColor: '#FF0000',
  defaultRowHeight: 20,
  defaultColWidth: 15
});

Data Types

CellType

  • STRING - Text values
  • NUMBER - Numeric values
  • BOOLEAN - True/false values
  • DATE - Date values
  • PERCENTAGE - Percentage values
  • CURRENCY - Currency values

NumberFormat

  • GENERAL - Default format
  • NUMBER - Number with optional decimals
  • CURRENCY - Currency format
  • PERCENTAGE - Percentage format
  • DATE - Date format
  • TIME - Time format
  • CUSTOM - Custom format string

Styling

StyleBuilder

Fluent API for creating cell styles.

const style = StyleBuilder.create()
  .fontBold()
  .fontSize(12)
  .fontColor('#FF0000')
  .backgroundColor('#FFFF00')
  .border('thin', '#000000')
  .centerAlign()
  .verticalAlign('middle')
  .wrapText()
  .build();

🎯 Advanced Examples

Complex Report with Multiple Worksheets

import { ExcelBuilder, CellType, NumberFormat, StyleBuilder } from 'han-excel-builder';

const builder = new ExcelBuilder({
  author: 'Report Generator',
  company: 'Your Company'
});

// Summary worksheet
const summarySheet = builder.addWorksheet('Summary');
summarySheet.addHeader({
  key: 'title',
  value: 'Annual Report Summary',
  type: CellType.STRING,
  mergeCell: true,
  styles: StyleBuilder.create().fontBold().fontSize(18).centerAlign().build()
});

// Detailed worksheet
const detailSheet = builder.addWorksheet('Details');
detailSheet.addSubHeaders([
  { key: 'date', value: 'Date', type: CellType.DATE, width: 12 },
  { key: 'category', value: 'Category', type: CellType.STRING, width: 15 },
  { key: 'amount', value: 'Amount', type: CellType.NUMBER, width: 12, numberFormat: NumberFormat.CURRENCY },
  { key: 'percentage', value: '%', type: CellType.PERCENTAGE, width: 8 }
]);

// Add data with alternating row colors
data.forEach((row, index) => {
  const rowStyle = index % 2 === 0 
    ? StyleBuilder.create().backgroundColor('#F0F0F0').build()
    : undefined;
    
  detailSheet.addRow([
    { key: 'date', value: row.date, type: CellType.DATE },
    { key: 'category', value: row.category, type: CellType.STRING },
    { key: 'amount', value: row.amount, type: CellType.NUMBER },
    { key: 'percentage', value: row.percentage, type: CellType.PERCENTAGE }
  ], rowStyle);
});

await builder.generateAndDownload('annual-report');

Conditional Styling

const style = StyleBuilder.create()
  .conditionalFormat({
    type: 'cellIs',
    operator: 'greaterThan',
    values: [1000],
    style: StyleBuilder.create()
      .backgroundColor('#90EE90')
      .fontColor('#006400')
      .build()
  })
  .build();

🧪 Testing

# Run tests
npm test

# Run tests with coverage
npm run test:coverage

# Run tests in watch mode
npm run test:watch

🛠️ Development

# Install dependencies
npm install

# Start development server
npm run dev

# Build for production
npm run build

# Run linting
npm run lint

# Format code
npm run format

# Generate documentation
npm run docs

📋 Migration from legacy-excel

If you're migrating from the legacy version, here's a quick comparison:

// Legacy way
const worksheets: IWorksheets[] = [{
  name: "Report",
  tables: [{
    headers: [...],
    subHeaders: [...],
    body: [...],
    footers: [...]
  }]
}];
await fileBuilder(worksheets, "report");

// New way
const builder = new ExcelBuilder();
const worksheet = builder.addWorksheet('Report');
worksheet.addHeaders([...]);
worksheet.addSubHeaders([...]);
worksheet.addRows([...]);
await builder.generateAndDownload('report');

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🆘 Support


Made with ❤️ by the Han Excel Team