{"library":"node-excel-export","title":"Node.js Excel Export","description":"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.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install node-excel-export"],"cli":null},"imports":["const excel = require('node-excel-export');","const reportBuffer = excel.buildExport([...]);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const excel = require('node-excel-export');\nconst fs = require('fs');\n\n// You can define styles as json object\nconst styles = {\n  headerDark: {\n    fill: {\n      fgColor: {\n        rgb: 'FF000000'\n      }\n    },\n    font: {\n      color: {\n        rgb: 'FFFFFFFF'\n      },\n      sz: 14,\n      bold: true,\n      underline: true\n    }\n  },\n  cellPink: {\n    fill: {\n      fgColor: {\n        rgb: 'FFFFCCFF'\n      }\n    }\n  },\n  cellGreen: {\n    fill: {\n      fgColor: {\n        rgb: 'FF00FF00'\n      }\n    }\n  }\n};\n\n//Array of objects representing heading rows (very top)\nconst heading = [\n  [{value: 'a1', style: styles.headerDark}, {value: 'b1', style: styles.headerDark}, {value: 'c1', style: styles.headerDark}],\n  ['a2', 'b2', 'c2'] // <-- It can be only values\n];\n\n//Here you specify the export structure\nconst specification = {\n  customer_name: { \n    displayName: 'Customer', \n    headerStyle: styles.headerDark, \n    cellStyle: function(value, row) { \n      return (row.status_id == 1) ? styles.cellGreen : {fill: {fgColor: {rgb: 'FFFF0000'}}}; \n    },\n    width: 120 \n  },\n  status_id: {\n    displayName: 'Status',\n    headerStyle: styles.headerDark,\n    cellFormat: function(value, row) { \n      return (value == 1) ? 'Active' : 'Inactive';\n    },\n    width: '10' \n  },\n  note: {\n    displayName: 'Description',\n    headerStyle: styles.headerDark,\n    cellStyle: styles.cellPink, \n    width: 220 \n  }\n}\n\n// The data set should have the following shape (Array of Objects)\nconst dataset = [\n  {customer_name: 'IBM', status_id: 1, note: 'some note', misc: 'not shown'},\n  {customer_name: 'HP', status_id: 0, note: 'some note'},\n  {customer_name: 'MS', status_id: 0, note: 'some note', misc: 'not shown'}\n]\n\n// Define an array of merges.\nconst merges = [\n  { start: { row: 1, column: 1 }, end: { row: 1, column: 10 } },\n  { start: { row: 2, column: 1 }, end: { row: 2, column: 5 } },\n  { start: { row: 2, column: 6 }, end: { row: 2, column: 10 } }\n]\n\n// Create the excel report. This function will return a Buffer.\nconst report = excel.buildExport(\n  [\n    {\n      name: 'Report',\n      heading: heading,\n      merges: merges,\n      specification: specification,\n      data: dataset\n    }\n  ]\n);\n\n// Save the buffer to a file\nfs.writeFileSync('report.xlsx', report);\nconsole.log('report.xlsx created successfully.');","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}