excel-file-reader-browser-ts
A robust and efficient TypeScript utility
designed specifically for browser environments to read Excel files
(.xlsx, .xls) from user-uploaded File objects. This package provides
convenient functions to easily get the total number of rows, extract
sheet headers, and check if specific columns contain data, all
client-side.
Table of Contents Description
Features
Installation
Usage
Getting the File Object from User Input
Get Total Row Count
Get Headers
Check if Column is Populated
API Reference
Error Handling
Contributing
Demo Link
Description
excel-file-reader-browser-ts addresses the need for
client-side Excel file processing in web applications. Unlike
server-side solutions that rely on file paths, this package directly
works with File objects obtained from HTML <input type="file">
elements. It's built with TypeScript, offering strong type safety and
clear interfaces, making it ideal for Angular, React, Vue, and other
front-end frameworks.
It internally utilizes the browser-compatible features of the xlsx
library, abstracting away the complexities of FileReader and binary data
parsing, so you can focus on your application logic.
Features
Browser-Compatible: Works directly with File objects, no
Node.js fs module required.
Get Total Row Count: Quickly determine the total number of rows in an
Excel sheet, including headers.
Extract Headers: Retrieve the names of all columns from the first row of
a specified sheet.
Check Column Population: Verify if a column (identified by its header
name) contains any non-empty values in its data rows.
TypeScript Support: Fully typed for a better developer experience and
compile-time safety.
Promise-based API: All functions return Promises for easy asynchronous
handling.
Robust Error Handling: Provides clear error messages for issues like no
file selected, sheet not found, or header not found.
Installation To install excel-file-reader-browser-ts in your front-end
project, use npm or yarn:
npm install excel-file-reader-browser-ts xlsx
or
yarn add excel-file-reader-browser-ts xlsx
Note: While excel-file-reader-browser-ts handles xlsx internally, you
might still need to install xlsx directly if your project uses other
xlsx utilities.
Usage
import {
readFileAsArrayBuffer,
getExcelRowCount,
getExcelHeaders,
isExcelColumnPopulated,
findSpecialCharacterCells,
} from 'excel-file-reader-browser-ts';
// Inside class or function
// To Read the excel content as a array buffer
const buffer = await readFileAsArrayBuffer(file);
// Total Row count in excel sheet
const count = await getExcelRowCount(buffer);
// Headers only
const allHeaders = await getExcelHeaders(buffer);
// Is Any special chars are avaialble in the cells
const specialChars = await findSpecialCharacterCells(buffer);
// Get Number of Columns
const columnsCount = await getExcelColumnCount(buffer);
// Get Raw Data in a 2D array Format
const getRawData = await getExcelRawData(buffer)
Contributing
Contributions are welcome! If you find a bug or have a
feature request, please open an issue on the GitHub repository.
Demo Link
demo