Basic Usage
Learn the basics of xlmake.
Builder Pattern
xlmake uses a method chaining builder pattern.
import { xlmake } from "xlmake";
const output = await xlmake() // 1. Create builder
.sheet("Sheet Name") // 2. Add sheet
.table({ ... }) // 3. Add table
.getNode(); // 4. Get output object
await output.saveToFile("output.xlsx"); // 5. Save to file
Sheet Operations
Adding Sheets
xlmake().sheet("Sales Data") // With name
xlmake().sheet() // Auto-generated (Sheet1, Sheet2...)
Creating Multiple Sheets
const output = await xlmake()
.sheet("Sales")
.table({ ... })
.sheet("Stock") // Second sheet
.table({ ... })
.sheet("Customers") // Third sheet
.table({ ... })
.getNode();
Adding Tables
Basic Table
.table({
columns: [
{ key: "name", label: "Product" },
{ key: "price", label: "Price" },
],
data: [
{ name: "Apple", price: 100 },
{ name: "Orange", price: 80 },
],
})
Using Presets
.table({
preset: "basic", // Blue header + all borders
columns: [...],
data: [...],
})
Adding Text
.text("Simple text")
.text({
value: "Styled text",
style: { bold: true, fontSize: 14 }
})
Adding Empty Rows
.space() // 1 empty row
.space(3) // 3 empty rows
Output
Node.js
const output = await xlmake()
.sheet("Data")
.table({ ... })
.getNode();
// Save to file
await output.saveToFile("report.xlsx");
// Get as Buffer (for API responses)
const buffer = await output.toBuffer();
Browser
const output = await xlmake()
.sheet("Data")
.table({ ... })
.getBrowser();
// Download
await output.download("report.xlsx");
Complete Example
import { xlmake } from "xlmake";
const salesData = [
{ name: "Apple", price: 100, quantity: 50 },
{ name: "Orange", price: 80, quantity: 100 },
{ name: "Banana", price: 120, quantity: 30 },
];
const output = await xlmake()
.sheet("Sales Report")
.text({ value: "Monthly Sales Report", style: { bold: true, fontSize: 16 } })
.text("January 2024")
.space(2)
.table({
preset: "basic",
columns: [
{ key: "name", label: "Product" },
{ key: "price", label: "Price" },
{ key: "quantity", label: "Quantity" },
],
data: salesData,
})
.space(1)
.text("* Prices exclude tax")
.getNode();
await output.saveToFile("sales-report.xlsx");
Next Steps
- Styling - Customize styles
- Multiple Sheets - Detailed multi-sheet usage
- API Overview - Available APIs