
Research
/Security News
60 Malicious Ruby Gems Used in Targeted Credential Theft Campaign
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
han-excel-builder
Advanced tools
Advanced Excel file generator with TypeScript support, comprehensive styling, and optimized performance
🚀 Advanced Excel file generator with TypeScript support, comprehensive styling, and optimized performance
A modern, fully-typed library for creating complex Excel reports with multiple worksheets, advanced styling, and high performance.
npm install han-excel-builder
# or
yarn add han-excel-builder
# or
pnpm add han-excel-builder
import { ExcelBuilder, CellType, NumberFormat, StyleBuilder } from 'han-excel-builder';
// Create a simple report
const builder = new ExcelBuilder();
const worksheet = builder.addWorksheet('Sales Report');
// Add headers
worksheet.addHeader({
key: 'title',
value: 'Monthly Sales Report',
type: CellType.STRING,
mergeCell: true,
styles: StyleBuilder.create()
.fontBold()
.fontSize(16)
.centerAlign()
.build()
});
// Add sub-headers
worksheet.addSubHeaders([
{
key: 'product',
value: 'Product',
type: CellType.STRING,
width: 20
},
{
key: 'sales',
value: 'Sales',
type: CellType.NUMBER,
width: 15,
numberFormat: NumberFormat.CURRENCY
}
]);
// Add data
worksheet.addRow([
{ key: 'product', value: 'Product A', type: CellType.STRING },
{ key: 'sales', value: 1500.50, type: CellType.NUMBER }
]);
// Generate and download
await builder.generateAndDownload('sales-report');
ExcelBuilder
Main class for creating Excel workbooks.
const builder = new ExcelBuilder({
author: 'Your Name',
company: 'Your Company',
created: new Date()
});
Worksheet
Represents a single worksheet in the workbook.
const worksheet = builder.addWorksheet('Sheet Name', {
tabColor: '#FF0000',
defaultRowHeight: 20,
defaultColWidth: 15
});
CellType
STRING
- Text valuesNUMBER
- Numeric valuesBOOLEAN
- True/false valuesDATE
- Date valuesPERCENTAGE
- Percentage valuesCURRENCY
- Currency valuesNumberFormat
GENERAL
- Default formatNUMBER
- Number with optional decimalsCURRENCY
- Currency formatPERCENTAGE
- Percentage formatDATE
- Date formatTIME
- Time formatCUSTOM
- Custom format stringStyleBuilder
Fluent API for creating cell styles.
const style = StyleBuilder.create()
.fontBold()
.fontSize(12)
.fontColor('#FF0000')
.backgroundColor('#FFFF00')
.border('thin', '#000000')
.centerAlign()
.verticalAlign('middle')
.wrapText()
.build();
import { ExcelBuilder, CellType, NumberFormat, StyleBuilder } from 'han-excel-builder';
const builder = new ExcelBuilder({
author: 'Report Generator',
company: 'Your Company'
});
// Summary worksheet
const summarySheet = builder.addWorksheet('Summary');
summarySheet.addHeader({
key: 'title',
value: 'Annual Report Summary',
type: CellType.STRING,
mergeCell: true,
styles: StyleBuilder.create().fontBold().fontSize(18).centerAlign().build()
});
// Detailed worksheet
const detailSheet = builder.addWorksheet('Details');
detailSheet.addSubHeaders([
{ key: 'date', value: 'Date', type: CellType.DATE, width: 12 },
{ key: 'category', value: 'Category', type: CellType.STRING, width: 15 },
{ key: 'amount', value: 'Amount', type: CellType.NUMBER, width: 12, numberFormat: NumberFormat.CURRENCY },
{ key: 'percentage', value: '%', type: CellType.PERCENTAGE, width: 8 }
]);
// Add data with alternating row colors
data.forEach((row, index) => {
const rowStyle = index % 2 === 0
? StyleBuilder.create().backgroundColor('#F0F0F0').build()
: undefined;
detailSheet.addRow([
{ key: 'date', value: row.date, type: CellType.DATE },
{ key: 'category', value: row.category, type: CellType.STRING },
{ key: 'amount', value: row.amount, type: CellType.NUMBER },
{ key: 'percentage', value: row.percentage, type: CellType.PERCENTAGE }
], rowStyle);
});
await builder.generateAndDownload('annual-report');
const style = StyleBuilder.create()
.conditionalFormat({
type: 'cellIs',
operator: 'greaterThan',
values: [1000],
style: StyleBuilder.create()
.backgroundColor('#90EE90')
.fontColor('#006400')
.build()
})
.build();
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watch
# Install dependencies
npm install
# Start development server
npm run dev
# Build for production
npm run build
# Run linting
npm run lint
# Format code
npm run format
# Generate documentation
npm run docs
If you're migrating from the legacy version, here's a quick comparison:
// Legacy way
const worksheets: IWorksheets[] = [{
name: "Report",
tables: [{
headers: [...],
subHeaders: [...],
body: [...],
footers: [...]
}]
}];
await fileBuilder(worksheets, "report");
// New way
const builder = new ExcelBuilder();
const worksheet = builder.addWorksheet('Report');
worksheet.addHeaders([...]);
worksheet.addSubHeaders([...]);
worksheet.addRows([...]);
await builder.generateAndDownload('report');
git checkout -b feature/amazing-feature
)git commit -m 'Add amazing feature'
)git push origin feature/amazing-feature
)This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ by the Han Excel Team
FAQs
Advanced Excel file generator with TypeScript support, comprehensive styling, and optimized performance
The npm package han-excel-builder receives a total of 8 weekly downloads. As such, han-excel-builder popularity was classified as not popular.
We found that han-excel-builder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.