base64-to-excel
v1.2.1
Published
Download Excel (.xlsx) file from Base64 string in browser
Maintainers
Readme
📦 base64-to-excel
A lightweight browser utility to download Excel (.xlsx) files from Base64 strings.
This package is useful when your backend API returns Excel files encoded as Base64 and you want to trigger a file download on the client side.
✨ Features
- Converts Base64 string to Excel file
- Automatically triggers file download
- Zero external dependencies
- Written in TypeScript
- Works with React, Vite, Vue, Angular, and plain JavaScript
📥 Installation
npm install base64-to-excel🚀 Usage
Basic Example
import base64ToExcel from "base64-to-excel";
base64ToExcel(base64String, "report.xlsx");React Example
import base64ToExcel from "base64-to-excel";
const downloadExcel = async () => {
const response = await fetch("/api/excel");
const result = await response.json();
base64ToExcel(result.base64, "users.xlsx");
};🧾 API
base64ToExcel(base64Data, fileName?)
| Name | Type | Description |
|----|----|----|
| base64Data | string | Base64 encoded Excel data |
| fileName | string | Optional file name (default: Sample.xlsx) |
🌐 Environment Support
| Environment | Supported | |-----------|-----------| | Browser | ✅ Yes | | React / Vite | ✅ Yes | | Vue / Angular | ✅ Yes | | Next.js (Client Side) | ✅ Yes | | Node.js | ❌ No |
⚠️ This package uses browser APIs such as
window,document,Blob, andatob.
It will not work in Node.js or server environments.
🔒 Error Handling
try {
base64ToExcel(base64Data, "file.xlsx");
} catch (error) {
console.error("Failed to download Excel file", error);
}🧑💻 Author
Anand Pandey
GitHub: https://github.com/Anandpandey400
📜 License
MIT License © 2025 Anand Pandey
