Skip to the content.

xlsx-js-style

ℹ️ About

SheetJS with Style! Create Excel spreadsheets with basic styling options using JavaScript.

This project is a fork of gitbrent/xlsx-js-style, which is a fork of SheetJS/sheetjs combined with code from sheetjs-style (by ShanaMaid) and sheetjs-style-v2 (by Raul Gonzalez).

All projects are under the Apache 2.0 License

🔌 Installation

Install npm:

npm install @redoper1/xlsx-js-style

Install browser:

<script lang="javascript" src="dist/xlsx.min.cjs"></script>

🗒 Core API

🗒 Style API

Cell Style Demo

Browser Demo

Cell Style Example

ws["A1"].s = {
  font: {
    name: "Calibri",
    sz: 24,
    bold: true,
    color: { rgb: "FFFFAA00" },
  },
};

Cell Style Properties

Cell styles are specified by a style object that roughly parallels the OpenXML structure. The style object has five top-level attributes: alignment, border, fill, font and numFmt.

Style Attribute Sub Attributes Default Values/description
alignment vertical bottom "top" or "center" or "bottom"
  horizontal left "left" or "center" or "right"
  wrapText false true or false
  readingOrder   2 // for right-to-left
  textRotation 0 Number from 0 to 180 or 255
      45 is rotated up 45 degrees
      90 is rotated up 90 degrees
      135 is rotated down 45 degrees
      180 is rotated down 180 degrees
      255 is special, aligned vertically
border top   { style: BORDER_STYLE, color: COLOR_SPEC }
  bottom   { style: BORDER_STYLE, color: COLOR_SPEC }
  left   { style: BORDER_STYLE, color: COLOR_SPEC }
  right   { style: BORDER_STYLE, color: COLOR_SPEC }
  diagonal   { style: BORDER_STYLE, color: COLOR_SPEC }
  diagonalUp   true or false
  diagonalDown   true or false
fill patternType "none" "solid" or "none"
  fgColor   foreground color: see COLOR_SPEC
  bgColor   background color: seeCOLOR_SPEC
font bold   font boldtrue or false
  color   font color COLOR_SPEC
  italic false font italic true or false
  name "Calibri" font name
  strike false font strikethrough true or false
  sz "11" font size (points)
  underline false font underline true or false
  vertAlign   "superscript" or "subscript"
numFmt   0 "0" // integer index to built in formats, see StyleBuilder.SSF property
      "0.00%" // string matching a built-in format, see StyleBuilder.SSF
      "0.0%" // string specifying a custom format
      "0.00%;\\(0.00%\\);\\-;@" // string specifying a custom format, escaping special characters
      "m/dd/yy" // string a date format using Excel’s format notation

COLOR_SPEC: Colors for fill, font, and border are specified as objects, either:

BORDER_STYLE: Border style is a string value which may take on one of the following values:

Border Notes

Borders for merged areas are specified for each cell within the merged area. For example, to apply a box border to a merged area of 3x3 cells, border styles would need to be specified for eight different cells:

🙏 Thanks

🔖 License

Please consult the attached LICENSE file for details. All rights not explicitly granted by the Apache 2.0 License are reserved by the Original Author.