Registry / data / node-excel-export

node-excel-export

JSON →
library1.4.4jsnpmunverified

node-excel-export is a Node.js module designed for generating `.xlsx` files from JavaScript datasets. It takes an array of objects as input along with a JSON-based report specification, allowing for flexible configuration of column headers, data mapping, and cell styling. The current stable version is 1.4.4. While its release cadence appears to be slow, suggesting a mature and largely feature-complete library, it remains functional for its stated purpose. Key differentiators include its ability to apply rich cell styling, dynamically reformat data using renderer functions, and define complex header rows and cell merges directly from a JavaScript configuration. It abstracts away the complexities of the underlying `xlsx` (js-xlsx) library for common export scenarios, providing a simpler API for generating Excel reports on the server side.

npm install node-excel-export
INSTALL
IMPORT
SIG · NODE-EXCEL-EXPORT
N
node-excel-export
datajavascriptv1.4.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

excel
const excel = require('node-excel-export');
import excel from 'node-excel-export';
This package is CommonJS-only. Direct ESM imports are not supported without transpilation or Node.js's createRequire utility.
buildExport
const reportBuffer = excel.buildExport([...]);
import { buildExport } from 'node-excel-export';
buildExport is a method on the default CommonJS export, not a named export. Ensure you import the entire module first.

This quickstart demonstrates how to define styles, create heading rows, specify column structures, and generate an Excel (.xlsx) file from a dataset, saving it to disk.

const excel = require('node-excel-export'); const fs = require('fs'); // You can define styles as json object const styles = { headerDark: { fill: { fgColor: { rgb: 'FF000000' } }, font: { color: { rgb: 'FFFFFFFF' }, sz: 14, bold: true, underline: true } }, cellPink: { fill: { fgColor: { rgb: 'FFFFCCFF' } } }, cellGreen: { fill: { fgColor: { rgb: 'FF00FF00' } } } }; //Array of objects representing heading rows (very top) const heading = [ [{value: 'a1', style: styles.headerDark}, {value: 'b1', style: styles.headerDark}, {value: 'c1', style: styles.headerDark}], ['a2', 'b2', 'c2'] // <-- It can be only values ]; //Here you specify the export structure const specification = { customer_name: { displayName: 'Customer', headerStyle: styles.headerDark, cellStyle: function(value, row) { return (row.status_id == 1) ? styles.cellGreen : {fill: {fgColor: {rgb: 'FFFF0000'}}}; }, width: 120 }, status_id: { displayName: 'Status', headerStyle: styles.headerDark, cellFormat: function(value, row) { return (value == 1) ? 'Active' : 'Inactive'; }, width: '10' }, note: { displayName: 'Description', headerStyle: styles.headerDark, cellStyle: styles.cellPink, width: 220 } } // The data set should have the following shape (Array of Objects) const dataset = [ {customer_name: 'IBM', status_id: 1, note: 'some note', misc: 'not shown'}, {customer_name: 'HP', status_id: 0, note: 'some note'}, {customer_name: 'MS', status_id: 0, note: 'some note', misc: 'not shown'} ] // Define an array of merges. const merges = [ { start: { row: 1, column: 1 }, end: { row: 1, column: 10 } }, { start: { row: 2, column: 1 }, end: { row: 2, column: 5 } }, { start: { row: 2, column: 6 }, end: { row: 2, column: 10 } } ] // Create the excel report. This function will return a Buffer. const report = excel.buildExport( [ { name: 'Report', heading: heading, merges: merges, specification: specification, data: dataset } ] ); // Save the buffer to a file fs.writeFileSync('report.xlsx', report); console.log('report.xlsx created successfully.');
Debug
Known issues
gotchaThis package is CommonJS-only. Attempting to use `import` syntax directly in an ESM module without proper configuration (like `createRequire` or `type: "commonjs"` in package.json for the entry file) will result in errors.
fix
Use `const excel = require('node-excel-export');` for importing the module in CommonJS environments.
affects: >=1.0.0
gotchaDynamic styling or formatting functions (`cellStyle`, `cellFormat`) must return valid style objects or formatted strings. Errors within these functions can lead to malformed Excel files or runtime exceptions during report generation.
fix
Thoroughly test `cellStyle` and `cellFormat` functions with various data inputs to ensure they always return expected values or style objects according to the `xlsx` library's specifications. Always include a fallback or default style.
affects: >=1.0.0
gotchaThe `specification` object's keys must exactly match the keys in your `dataset` objects for data to be correctly mapped to columns. Mismatched keys will result in empty cells.
fix
Verify that all keys defined in the `specification` object (e.g., `customer_name`, `status_id`) correspond precisely to the property names in your `dataset` array of objects.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: excel.buildExport is not a function
Attempting to use `buildExport` as a named import or calling it on a non-module object, often due to incorrect CommonJS import syntax in an ESM context.
fix
Ensure you are importing the module using `const excel = require('node-excel-export');` and then calling `excel.buildExport(...)`.
Error: Invalid data or specification provided. Check your dataset and specification objects.
The `dataset` is not an array of objects, or the `specification` object is malformed or missing required properties, leading to `node-excel-export` failing to process the input correctly.
fix
Review your `dataset` to confirm it's an `Array<Object>` and your `specification` to ensure all properties like `displayName`, `headerStyle`, and `width` are correctly defined as shown in the documentation.
The file cannot be opened because there are problems with the contents.
Generated Excel file is corrupt, often due to invalid data types passed to `xlsx` library, errors in custom `cellStyle` or `cellFormat` functions, or incorrect merge ranges.
fix
Double-check the data types in your `dataset`, ensure custom style/format functions return valid output, and confirm `merges` array defines valid row/column ranges without overlaps that could cause structural issues.
Upgrade
Version history
1.4.4latest on npm
Audit
Dependencies
xlsxrequiredCore dependency for creating and manipulating Excel files.
lodashrequiredUtility library used internally for data manipulation.
file-saveroptionalPotentially used for client-side file saving in browser contexts, though not strictly required for Node.js server-side export.
Agent activity
2 hits · last 30 days
node
2
Resources
node-excel-export — npm install node-excel-export · libregistry