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

@bkfullstack/table-to-excel

v1.0.10

Published

A library to convert HTML tables to Excel with inline styles (TypeScript supported).

Readme

HTML to Excel Converter

This project provides a utility to convert HTML tables into Excel spreadsheets, complete with styles like background colors and font colors. The generated file can be returned as a Blob, making it compatible with both Node.js and browser environments.


Features

  • Parses HTML tables and converts them to Excel files.
  • Supports inline styles like background-color,color,text-align,border,colspan,rowspan.
  • Works in both Node.js and browser environments.
  • Returns the Excel file as a Blob or File.

Installation

Install the package using npm:

npm install @bkfullstack/table-to-excel

Usage

Node.js Example

import { htmlToExcelBlob, htmlToExcelFile } from '@bkfullstack/table-to-excel';
import fs from 'fs';

const html = `
<table>
  <tr>
    <th style="background-color: #ff9999; color: white;">Name</th>
    <th style="background-color: #ff9999; color: white;">Age</th>
  </tr>
  <tr>
    <td style="background-color: #ffe6e6;">John</td>
    <td style="background-color: #ffe6e6;">30</td>
  </tr>
</table>
`;

htmlToExcelBlob(html).then(async (blob) => {
  const buffer = Buffer.from(await blob.arrayBuffer());
  fs.writeFileSync('output.xlsx', buffer);
  console.log('Excel file created successfully as output.xlsx');
});

htmlToExcelFile(html, 'output.xlsx').then(async (file) => {
  console.log('Excel file created successfully as output.xlsx');
}).catch((error) => {
  console.error('Error creating Excel file:', error);
});

Browser Example

import { htmlToExcelBlob } from '@bkfullstack/table-to-excel';

const html = `
<table>
  <tr>
    <th style="background-color: #ff9999; color: white;">Name</th>
    <th style="background-color: #ff9999; color: white;">Age</th>
  </tr>
  <tr>
    <td style="background-color: #ffe6e6;">John</td>
    <td style="background-color: #ffe6e6;">30</td>
  </tr>
</table>
`;

htmlToExcelBlob(html).then((blob) => {
  const url = URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = url;
  a.download = 'output.xlsx';
  document.body.appendChild(a);
  a.click();
  document.body.removeChild(a);
  console.log('Excel file downloaded successfully');
});

API

htmlToExcelBlob(html: string): Promise<Blob>

Converts an HTML string containing a <table> to an Excel file and returns it as a Blob.

Parameters:

  • html (string): The HTML string containing the table to convert.

Returns:

  • Promise<Blob>: A Blob representing the Excel file.

htmlToExcelFile(html: string, outputFilePath: string): Promise<void>

Converts an HTML string containing a <table> to an Excel file and returns it as a Blob.

Parameters:

  • html (string): The HTML string containing the table to convert.
  • outputFilePath (string): The path to the output file.

Returns:

  • Promise<void>: A Promise that resolves when the Excel file is created.

Requirements

  • Node.js 18 or later (for Node.js usage).
  • A modern browser (for browser usage).

License

This project is licensed under the MIT License.


Acknowledgments

  • ExcelJS for Excel file generation.
  • JSDOM for HTML parsing in Node.js.

Enjoy converting HTML tables to Excel with ease!