{"library":"node-xlsx","title":"NodeJS Excel Parser & Builder","description":"node-xlsx is a Node.js library that serves as a straightforward wrapper around the powerful SheetJS xlsx module, enabling developers to parse and build Excel (XLSX) files efficiently. It simplifies common operations like reading data from existing Excel files (either from a file path or a buffer) and generating new Excel files from structured JavaScript data. The library supports advanced features such as defining custom column widths and merging cells. Built with TypeScript, node-xlsx provides robust static type checking, enhancing development safety and maintainability. The current stable version is 0.24.0, with recent updates focused on modernizing its internal stack and ensuring compatibility with the latest versions of its underlying xlsx dependency. It differentiates itself by providing a simpler, Node.js-specific interface to the comprehensive SheetJS library, abstracting away some of the complexities of the core `xlsx` package.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-xlsx"],"cli":null},"imports":["import xlsx from 'node-xlsx';","import xlsx from 'node-xlsx';\nconst parsedData = xlsx.parse(bufferOrPath);","import xlsx from 'node-xlsx';\nconst buffer = xlsx.build(data);","import type { WorkSheet } from 'node-xlsx';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import xlsx from 'node-xlsx';\nimport fs from 'node:fs';\n\nconst filePath = './myFile.xlsx';\n\n// Create a dummy Excel file for parsing example\nconst dataToBuild = [\n  [1, 2, 3],\n  [true, false, null, 'sheetjs'],\n  ['foo', 'bar', new Date('2014-02-19T14:30Z'), '0.3']\n];\nconst bufferToSave = xlsx.build([{name: 'Test Sheet', data: dataToBuild}]);\nfs.writeFileSync(filePath, bufferToSave);\nconsole.log('Dummy Excel file created at', filePath);\n\n// 1. Parse an xlsx file from a buffer\nconst workSheetsFromBuffer = xlsx.parse(fs.readFileSync(filePath));\nconsole.log('Parsed from buffer:', JSON.stringify(workSheetsFromBuffer, null, 2));\n\n// 2. Parse an xlsx file directly from a file path\nconst workSheetsFromFile = xlsx.parse(filePath);\nconsole.log('Parsed from file path:', JSON.stringify(workSheetsFromFile, null, 2));\n\n// 3. Build an xlsx file with custom options and save it\nconst complexData = [\n  ['Header A', 'Header B'],\n  ['Value 1', 'Longer Value 2'],\n  ['Short', 'Another Value']\n];\nconst sheetOptions = {'!cols': [{wch: 10}, {wch: 25}]}; // Custom column widths\nconst mergedBuffer = xlsx.build([{\n  name: 'Custom Sheet',\n  data: complexData,\n  options: sheetOptions\n}]);\nconst outputFilePath = './customOutput.xlsx';\nfs.writeFileSync(outputFilePath, mergedBuffer);\nconsole.log('Custom Excel file created at', outputFilePath);\n\n// Clean up dummy file (optional)\nfs.unlinkSync(filePath);\nfs.unlinkSync(outputFilePath);\nconsole.log('Cleaned up dummy files.');","lang":"typescript","description":"This quickstart demonstrates how to create a simple Excel file, then parse its contents both from a buffer and directly from a file path, and finally build another Excel file with custom column widths using `node-xlsx`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}