xlsx-downloader
v1.0.5
Published
A wrapper for ExcelJS to simplify Excel file generation
Downloads
62
Readme
📊 Excel Downloader: ExcelJS Wrapper for Spreadsheet Sorcery! 🧙♂️
Excel Downloader is a magical wrapper around the powerful ExcelJS library, designed to simplify your spreadsheet creation process. Turn data into Excel files with a flick of your wand!
🚀 Installation
Summon this package to your project with:
npm install xlsx-downloader
🎭 Usage: Excel-erate Your Workflow!
Here's how to conjure your first magical spreadsheet:
import { ExcelGenerator } from "xlsx-downloader";
// Prepare your data
const sheetsData = [
{
headers: ["Wizard Name", "Spells Known", "Favorite Potion"], // Specify headers
data: [
["Gandalf", 1000, "Earl Grey Tea"],
["Harry Potter", 31, "Butterbeer"],
["Dr. Strange", 678, "Green Smoothie"],
], // Specify the sheet data
header_format: { font: { bold: true, color: { argb: "FF7F50FF" } } }, // Specify header format
sheet_name: "Wizarding World", // Specify the sheet name
column_widths: [15, 25, 10] // Specify widths for each column
},
];
// Create the Excel file
const excelGenerator = new ExcelGenerator(sheetsData);
excelGenerator.generate().then((buffer) => {
// In a Node.js environment, save the file
require("fs").writeFileSync("wizard_data.xlsx", buffer);
console.log("🎉 Wizard data successfully catalogued!");
// In a browser environment, trigger a download
// const blob = new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
// const url = window.URL.createObjectURL(blob);
// const a = document.createElement('a');
// a.href = url;
// a.download = 'wizard_data.xlsx';
// a.click();
});
🧙♀️ Casting More Complex Spells
Need multiple sheets or fancy formatting? No problem!
const advancedSheetsData = [
{
headers: ["Potion", "Ingredients", "Brewing Time (hours)"],
data: [
["Love Potion", "Rose petals, Unicorn hair", 72],
["Invisibility Elixir", "Moonstone, Ghost essence", 168],
["Dragon Breath", "Chili peppers, Dragon scales", 24],
],
header_format: {
font: { bold: true, color: { argb: "FFFFFFFF" } },
fill: {
type: "pattern",
pattern: "solid",
fgColor: { argb: "FF800080" },
},
},
sheet_name: "Potions",
},
{
headers: ["Spell", "Difficulty", "Power Level"],
data: [
["Wingardium Leviosa", "Beginner", 3],
["Expecto Patronum", "Advanced", 10],
["Avada Kedavra", "Unforgivable", 100],
],
header_format: {
font: { bold: true, italic: true },
alignment: { horizontal: "center" },
},
sheet_name: "Spellbook",
},
];
const advancedExcel = new ExcelGenerator(advancedSheetsData);
advancedExcel.generate().then((buffer) => {
// Save or download your multi-sheet, formatted Excel file
});
🎩 Tips and Tricks
- Sheet Names: Each sheet must have a unique name. Choose wisely!
- Header Formatting: Make your headers stand out with custom styles. Our wrapper simplifies ExcelJS's styling options.
- Data Types: Numbers, strings, and dates are all welcome in your data arrays, just like in ExcelJS.
- Buffer Handling: The
generate()
method returns a Promise that resolves to a Buffer, consistent with ExcelJS's output.
🔮 Why Use This Wrapper?
Excel Downloader simplifies the process of creating Excel files with ExcelJS. It provides:
- A streamlined API for quick Excel file generation
- Easy multi-sheet creation
- Simplified header formatting
- Consistent interface for both Node.js and browser environments
While it doesn't expose all of ExcelJS's features, it covers the most common use cases for generating downloadable Excel files.
📚 ExcelJS Documentation
For more advanced features or direct ExcelJS usage, refer to the official ExcelJS documentation.
📜 License
MIT (Magical Institute of Technology)
Remember, this wrapper brings the magic of ExcelJS to your fingertips with a simpler spell. Use it wisely, and may your data always flow smoothly! 🧙♂️✨