const workbook = XLSX.utils.book_new(); const worksheet = XLSX.utils.aoa_to_sheet([ [ v: "Styled Cell", s: font: bold: true, color: rgb: "FF0000" , // Red Bold Text fill: fgColor: rgb: "E9E9E9" , // Gray Background alignment: horizontal: "center" // Centered ] ]); XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1"); ``` ### Common Style Properties | Property | Sub-Properties | Description | | :--- | :--- | :--- | | **fill** | `patternType`, `fgColor` | Sets background color and pattern. | | **font** | `name`, `sz`, `bold`, `color` | Defines typeface, size, weight, and text color. | | **alignment** | `vertical`, `horizontal`, `wrapText` | Controls text position and line wrapping. | | **border** | `top`, `bottom`, `left`, `right` | Adds lines around the cell. | ### Important Security & Version Note The original `xlsx-style` package hasn't been updated in several years and may contain security vulnerabilities or compatibility issues with newer versions of Node.js. For modern applications, many developers now recommend **modern alternatives** that are actively maintained: * **[xlsx-js-style](https://npmjs.com):** A more recent fork that fixes many common bugs found in the original `xlsx-style`. * **[ExcelJS](https://npmjs.com):** A powerful, stand-alone library designed from the ground up to support advanced formatting, images, and complex templates. Would you like a full **code template** for a specific framework like **React** or **Angular** to get started faster? Use code with caution. xlsx-style - NPM
If you are looking to , you are likely trying to add visual flair—like colors, borders, and custom fonts—to Excel files generated via JavaScript. While the standard SheetJS (xlsx) library is excellent for data handling, its community version does not support cell styling. download xlsx-style
Once installed, you can apply styles by adding a s (style) object to any cell. This object can contain properties for fills, fonts, alignment, and borders. javascript const workbook = XLSX
xlsx-style is a popular fork of the original SheetJS project. It was specifically extended to allow developers to read and write cell formats (styles) to .xlsx workbooks. How to Download and Install | | **border** | `top`, `bottom`, `left`, `right`
You can include the script directly using a CDN like jsDelivr or by linking to the local file: ``` Use code with caution. How to Use xlsx-style for Styling