Socket
Book a DemoInstallSign in
Socket

xlsx-to-js

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xlsx-to-js

A TypeScript-based library for parsing Excel (XLSX) with browser support

1.0.4
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Xlsx-to-js

A TypeScript-based library for parsing Excel (XLSX) with browser support.

Getting Started

Installation

With npm:

npm install --save xlsx-to-js

Import library:

import { XlsxParser } from "xlsx-to-js";

Usage

Parsing Workbooks

Extract data from spreadsheet bytes

const xlsxParser = new XlsxParser();
const workbook = await xlsxParser.readFile(file, { dense: true, styles: true, drawings: true, skipHiddenRows: true });

The readFile method extract data from spreadsheet bytes stored in a ArrayBuffer.

The second argument to options accepts the properties:

OptionDefaultDescription
densefalseWhen the option dense: false is passed, parsers will skip empty cells.
stylesfalseWhen the opction styles: false is passed, parsers will skip cell styles.
drawingsfalseWhen the option drawings: false is passed, parsers will skip parsing drawings and graphical objects.
skipHiddenRowsfalseWhen the option skipHiddenRows: true is passed, hidden rows will be ignored during parsing.

Render to HTML

Render the parsed workbook as Excel-like HTML.

  • Render all sheets at once:
const xlsxParser = new XlsxParser();
const workbook = await xlsxParser.readFile(file, {
  dense: true,
  styles: true,
  drawings: true,
  skipHiddenRows: true,
});

const fullHtml = xlsxParser.toHTML(workbook);
document.getElementById('container')!.innerHTML = fullHtml;
  • Render a single sheet (recommended for performance in UIs with tabs):
const xlsxParser = new XlsxParser();
const workbook = await xlsxParser.readFile(file, {
  dense: true,
  styles: true,
  drawings: true,
  skipHiddenRows: true,
});

// Render first sheet (index 0)
const sheetHtml = xlsxParser.toHTMLSheet(workbook, 0);
document.getElementById('sheetView')!.innerHTML = sheetHtml;

Notes:

  • Pass styles: true to include cell fonts, colors, alignment, borders, and fills.
  • Pass drawings: true to include images, shapes, and textboxes positioned like in Excel.
  • The generated HTML includes column letters and row numbers. It also respects merged cells and most layout details.

Supported Features

  • Cell Content: strings, numbers, dates (basic serial-date -> locale string), formulas (stored, not evaluated).
  • Merged Cells: respects merge ranges and renders proper rowspan/colspan.
  • Styles: font family/size, bold/italic, text color, background fill (theme, rgb), horizontal/vertical alignment, wrap, borders (most styles) when styles: true.
  • Dimensions: column widths and row heights converted to pixels with Excel-like logic; honors per-column/row overrides and hidden/collapsed.
  • Headers: row numbers and column letters like Excel.
  • Drawings: images (png/jpg/gif), shapes (fill/border), textboxes (text color, align, font), positioned via anchors when drawings: true.
  • Multiple Sheets: render all or one at a time (toHTMLSheet).

Limitations

  • No Calc Engine: formulas are not evaluated; cell .formula is exposed, .value is parsed text/number/date.
  • Styles Fidelity: border variants, distributed/justify vertical alignment, and some number formats may not fully match Excel.
  • Themes/Tint: theme shade/tint handled pragmáticamente; minor color differences possible versus desktop Excel.
  • Fonts/MDW: column width conversion depends on runtime font metrics; small pixel drifts may occur across platforms.
  • Drawings Coverage: connectors, grouped shapes, rotations, and complex effects are not fully rendered.
  • Hidden Rows/Cols: when skipHiddenRows: true, hidden rows are skipped; hidden columns get width 0 but still occupy position.
  • Print/Views: print areas, panes freeze, page breaks and advanced view options are not applied to HTML.

Supported Environments

  • Browsers: modern Chromium/Firefox/Safari (ES2019+, DOMParser, Canvas for font metrics). Tested on latest Chrome/Edge/Firefox/Safari.
  • Node.js: intended for browser use. In Node you must polyfill DOMParser (e.g., jsdom) to use XML parsing and HTML rendering.
  • Module Format: published as ESM; works with bundlers like Vite/Webpack/Rollup.

References

  • ISO/IEC 29500:2012 "Office Open XML File Formats — Fundamentals And Markup Language Reference"

Keywords

excel

FAQs

Package last updated on 16 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.