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 🙏

© 2024 – Pkg Stats / Ryan Hefner

exceljs-wrpper-to-excel-export

v1.0.8

Published

A simple Excel export utility using ExcelJS

Downloads

247

Readme

Installation

Install the package via npm:

`npm install exceljs-wrpper-to-excel-export`

Usage Here’s an example of how to use the wrapper in your project:

Steps 1. Import the Package

import { excelJsWrapperToExcelExport } from "exceljs-wrpper-to-excel-export";

2. Define Configuration

3. Call The wrapper function excelJsWrapperToExcelExport with file name and config parameters

  excelJsWrapperToExcelExport("Example.xlsx", sheetConfigs);

Basic Configuration The wrapper function excelJsWrapperToExcelExport accepts two main parameters:

  1. fileName,
  2. sheetConfigs

Here’s a breakdown of the configuration for each sheet.

Example Configuration:

interface ColumnConfig {
  header: string;
  headerStyle?: ExcelJS.Style;

  key: string;
  type?: string;  //like 'date','string' default is 'string'
  width?: number;
  style?: ExcelJS.Style;
  formula?: string;

  sum?: boolean;
  sumColumnCellStyle?: ExcelJS.Style;

  dateFormat?: string; // Default "mm/dd/yyyy"
}
Config {
  columns: ColumnConfig[];
  autoAdjustColumnsWidth?: boolean;
  maxColumnWidth?: number;

  groupBy?: string;
  groupHeaderRow?: boolean;
  groupTotalLable?: string; // Default value is "Total"
  groupTotalLableCell?: string; // Default cell is "A"
  groupSumRowStyle?: ExcelJS.Style;
}
interface Data {
  [key: string]: any;
}
 interface SheetConfig {
  name: string; // sheet name
  config: Config; // sheet config
  data: Data[]; // data array
  extraHeaders?: ExtraHeader[];
}

Extra Headers Extra headers are rows above the column headers, allowing for merged cells and custom styles.

interface ExtraHeader {
  values: string[];
  mergeAcross: number[];
  style: ExcelJS.Style;
}

Extra Headers Example:

extraHeaders: [
  {
    values: ["Dashboard"],
    mergeAcross: [24],
    style: {
      font: { bold: true, size: 16 },
      alignment: { horizontal: "center" },
    },
  },
  {
    values: [
          "Contract Information",
	  "Financial Information",
          "Schedule Information"
     ],
    mergeAcross: [5, 4, 5],
    style: {
      font: { bold: true, size: 12 },
      alignment: { horizontal: "center" },
    },
  },
],

This will merge the specified columns to accommodate the header text across multiple columns.

Grouping and Summing To group data by a column and calculate sums:

  groupBy?: "groupColumn",
  groupHeaderRow?: true,
  groupTotalLable?: 'Total',
  groupTotalLableCell?: 'A',
  groupSumRowStyle?: ExcelJS.Style;

This configuration will automatically group data and generate a sum row for columns where sum: true is set. This configuration applied at column level.

Applying Formulas You can define formulas in the ColumnConfig:

formula: '{column}{row} * 2'

The placeholders {column} and {row} are automatically replaced by the actual cell references.

Date Formats Excel accepts various date format strings, including:

"mm/dd/yyyy": U.S. date format. "dd/mm/yyyy": European date format. "yyyy-mm-dd": ISO format. "mmmm dd, yyyy": Full month name (e.g., "September 12, 2024"). "d-mmm-yy": Short month name with year (e.g., "12-Sep-24"). "hh:mm:ss": Time format. "dd/mm/yyyy hh:mm:ss": Date and time combined.

Full Example

Here’s an example usage of the wrapper:

const sheetConfigs = [
  {
    name: "ExampleSheet",
    config: {
      columns: [
        { key: "id", header: "ID", width: 10 },
        { key: "name", header: "Name", width: 20, style: { font: { bold: true } } },
        { key: "date", header: "Date", type: "date", dateFormat: "dd/mm/yyyy" },
      ],
      groupBy: "category",
      groupHeaderRow: true,
      autoAdjustColumnsWidth: true,
    },
    data: [
      { id: 1, name: "John", date: "/Date(1635791400000)/", category: "A" },
      { id: 2, name: "Jane", date: "10/12/2024", category: "B" },
    ],
    extraHeaders: [
      {
        values: ["Extra Header 1", "Extra Header 2"],
        mergeAcross: [2, 1],
        style: {
          font: { bold: true, size: 14 },
          alignment: { horizontal: "center" },
        },
      },
    ],
  },
];

excelJsWrapperToExcelExport("Example.xlsx", sheetConfigs);

Error Handling The wrapper logs errors to the console and alerts users when something goes wrong. Ensure you have appropriate data validation to avoid issues like invalid configurations or missing columns.

Feel free to add any additional features or suggestions in the documentation as required.