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

@jjr-group/xlsx

v1.1.9

Published

A TypeScript library for generating Excel (.xlsx) files with custom formatting, headers, subheaders, body data, and footers.

Downloads

200

Readme

Excel Generation Library

A TypeScript library for generating Excel (.xlsx) files with custom formatting, headers, subheaders, body data, and footers.

Installation

npm install @jjr-group/xlsx
# or
yarn add @jjr-group/xlsx
# or
pnpm add @jjr-group/xlsx

Quick Start

import { fileBuilder, IHeader, IBody, IFooter, TYPECELL } from 'excel-generation-library';

// Create headers
const headers: IHeader[] = [
  {
    key: "title",
    type: TYPECELL.STRING,
    value: "SALES REPORT 2024",
    rowHeight: 40,
    mergeCell: true
  }
];

// Create subheaders with merged cells
const subHeaders: IHeader[] = [
  {
    key: "company",
    type: TYPECELL.STRING,
    value: "COMPANY",
    colWidth: 30
  },
  {
    key: "q1",
    type: TYPECELL.STRING,
    value: "Q1 2024",
    mergeCell: true,
    mergeTo: 3,
    childrens: [
      { key: "sales", type: TYPECELL.STRING, value: "SALES", colWidth: 15 },
      { key: "costs", type: TYPECELL.STRING, value: "COSTS", colWidth: 15 },
      { key: "profit", type: TYPECELL.STRING, value: "PROFIT", colWidth: 15 }
    ]
  }
];

// Create body data
const body: IBody[] = [
  {
    key: "company1",
    type: TYPECELL.STRING,
    value: "Company A",
    header: "company",
    jump: true,
    styles: { stripped: true },
    childrens: [
      {
        key: "q1_sales",
        type: TYPECELL.NUMBER,
        value: 150000,
        header: "sales",
        mainHeaderKey: "q1",
        styles: { stripped: true }
      }
    ]
  }
];

// Create footers
const footers: IFooter[] = [
  {
    key: "total",
    type: TYPECELL.STRING,
    value: "TOTAL",
    header: "company",
    mergeCell: true,
    mergeTo: 1
  }
];

// Generate Excel file
const generateReport = async () => {
  const worksheets = [{
    name: "Sales Report",
    tables: [{
      headers,
      subHeaders,
      body,
      footers,
      descriptionValues: [{
        title: "GENERATED ON",
        values: new Date().toLocaleDateString(),
        styles: { fontStyle: "bold", fontSize: 12 }
      }]
    }]
  }];

  await fileBuilder(worksheets, "Sales_Report_2024.xlsx");
};

// Use in button click
document.getElementById("download")?.addEventListener("click", generateReport);

API Reference

Core Functions

fileBuilder(worksheets, filename)

Generates the final Excel file.

Parameters:

  • worksheets: IWorksheets[] - Array of worksheet objects
  • filename: string - Output filename

Returns: Promise<void>

Interfaces

IHeader

interface IHeader {
  key: string;                    // Unique identifier
  type: TYPECELL;                // Cell type
  value: string | number;        // Display value
  colWidth?: number;             // Column width
  rowHeight?: number;            // Row height
  mergeCell?: boolean;           // Whether to merge cells
  mergeTo?: number;              // Number of columns to merge
  childrens?: IHeader[];         // Child subheaders
  mainHeaderKey?: string;        // Parent header key
  styles?: IStyles;              // Custom styles
}

IBody

interface IBody {
  key: string;                    // Unique identifier
  type: TYPECELL;                // Cell type
  value: string | number;        // Display value
  header: string;                // Corresponding header key
  jump?: boolean;                // Whether to jump to next row
  childrens?: IBody[];           // Child data
  mainHeaderKey?: string;        // Parent header key
  styles?: IStyles;              // Custom styles
  numberFormat?: NUMBERFORMATS;  // Number format
  link?: string;                 // Link (for TYPECELL.LINK)
}

IFooter

interface IFooter {
  key: string;                    // Unique identifier
  type: TYPECELL;                // Cell type
  value: string | number;        // Display value
  header: string;                // Corresponding header key
  mergeCell?: boolean;           // Whether to merge cells
  mergeTo?: number;              // Number of columns to merge
  styles?: IStyles;              // Custom styles
  numberFormat?: NUMBERFORMATS;  // Number format
  link?: string;                 // Link (for TYPECELL.LINK)
}

IStyles

interface IStyles {
  fontStyle?: "bold" | "italic" | "normal";
  fontSize?: number;
  fontColor?: string;
  backgroundColor?: string;
  stripped?: boolean;            // For alternating rows
  alignment?: "left" | "center" | "right";
  border?: {
    style?: "thin" | "medium" | "thick";
    color?: string;
  };
}

Enums

TYPECELL

enum TYPECELL {
  STRING = "string",
  NUMBER = "number",
  LINK = "link"
}

Features

  • ✅ Multiple worksheet support
  • ✅ Header and subheader merging
  • ✅ Custom cell formatting
  • ✅ Alternating row styles
  • ✅ Number formatting
  • ✅ Hyperlinks
  • ✅ Custom borders and colors
  • ✅ Description values for metadata
  • ✅ TypeScript support

Examples

Basic Table

const table = {
  headers: [{
    key: "title",
    type: TYPECELL.STRING,
    value: "Simple Table",
    mergeCell: true
  }],
  subHeaders: [{
    key: "name",
    type: TYPECELL.STRING,
    value: "Name",
    colWidth: 20
  }],
  body: [{
    key: "row1",
    type: TYPECELL.STRING,
    value: "John Doe",
    header: "name"
  }],
  footers: []
};

Complex Report with Merged Cells

const complexTable = {
  headers: [{
    key: "title",
    type: TYPECELL.STRING,
    value: "Financial Report",
    rowHeight: 40,
    mergeCell: true
  }],
  subHeaders: [
    {
      key: "company",
      type: TYPECELL.STRING,
      value: "Company",
      colWidth: 30
    },
    {
      key: "q1",
      type: TYPECELL.STRING,
      value: "Q1 2024",
      mergeCell: true,
      mergeTo: 3,
      childrens: [
        { key: "revenue", type: TYPECELL.STRING, value: "Revenue" },
        { key: "expenses", type: TYPECELL.STRING, value: "Expenses" },
        { key: "profit", type: TYPECELL.STRING, value: "Profit" }
      ]
    }
  ],
  body: [{
    key: "company1",
    type: TYPECELL.STRING,
    value: "Tech Corp",
    header: "company",
    jump: true,
    childrens: [
      {
        key: "q1_revenue",
        type: TYPECELL.NUMBER,
        value: 1000000,
        header: "revenue",
        mainHeaderKey: "q1",
        numberFormat: "#,##0"
      }
    ]
  }]
};

Browser Support

  • Chrome 60+
  • Firefox 55+
  • Safari 12+
  • Edge 79+

License

MIT

Contributing

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