|
2 | 2 |
|
3 | 3 | ## ℹ️ About |
4 | 4 |
|
5 | | -SheetJS with Style! Create Excel spreadsheets with basic styling options. |
| 5 | +SheetJS with Style! Create Excel spreadsheets with basic styling options using JavaScript. |
6 | 6 |
|
7 | | -This project is a fork of [SheetJS/sheetjs](https://github.com/sheetjs/sheetjs) combined with code from |
8 | | -[sheetjs-style](https://www.npmjs.com/package/sheetjs-style) (by [ShanaMaid](https://github.com/ShanaMaid/)) |
9 | | -and [sheetjs-style-v2](https://www.npmjs.com/package/sheetjs-style-v2) (by [Raul Gonzalez](https://www.npmjs.com/~armandourbina)). |
| 7 | +<p align="center"> |
| 8 | + <a href="https://github.com/gitbrent/xlsx-js-style/"> |
| 9 | + <img alt="xlsx-js-style sheetjs styles" title="xlsx-js-style sheetjs styles" src="https://raw.githubusercontent.com/gitbrent/xlsx-js-style/demos/browser/images/readme_banner.png"/> |
| 10 | + </a> |
| 11 | +</p> |
| 12 | +<br/> |
10 | 13 |
|
11 | | -All projects are under the Apache 2.0 License |
| 14 | +[](https://snyk.io/test/npm/xlsx-js-style) [](https://www.npmjs.com/package/xlsx-js-style) |
| 15 | +[](https://img.shields.io/npm/types/xlsx-js-style) |
12 | 16 |
|
13 | 17 | ## 🔌 Installation |
14 | 18 |
|
15 | 19 | Install [npm](https://www.npmjs.org/package/xlsx-js-style): |
16 | 20 |
|
17 | 21 | ```sh |
18 | | -npm install xlsx-js-style --save |
| 22 | +npm install xlsx-js-style |
19 | 23 | ``` |
20 | 24 |
|
21 | 25 | Install browser: |
22 | 26 |
|
23 | 27 | ```html |
24 | | -<script lang="javascript" src="dist/xlsx.bundle.js"></script> |
| 28 | +<script src="dist/xlsx.bundle.js"></script> |
25 | 29 | ``` |
26 | 30 |
|
27 | 31 | ## 🗒 Core API |
28 | 32 |
|
29 | | -Please refer to the [SheetJS](https://sheetjs.com/) documentation for core API reference. |
| 33 | +- Refer to the [SheetJS](https://sheetjs.com/) documentation for core API reference |
| 34 | +- Current version of sheetjs used: **0.18.5** |
30 | 35 |
|
31 | 36 | ## 🗒 Style API |
32 | 37 |
|
33 | 38 | ### Cell Style Example |
34 | 39 |
|
35 | 40 | ```js |
36 | | -ws["A1"].s = { |
37 | | - font: { |
38 | | - name: "Calibri", |
39 | | - sz: 24, |
40 | | - bold: true, |
41 | | - color: { rgb: "FFFFAA00" }, |
42 | | - }, |
43 | | -}; |
| 41 | +// STEP 1: Create a new workbook |
| 42 | +const wb = XLSX.utils.book_new(); |
| 43 | + |
| 44 | +// STEP 2: Create data rows and styles |
| 45 | +let row = [ |
| 46 | + { v: "Courier: 24", t: "s", s: { font: { name: "Courier", sz: 24 } } }, |
| 47 | + { v: "bold & color", t: "s", s: { font: { bold: true, color: { rgb: "FF0000" } } } }, |
| 48 | + { v: "fill: color", t: "s", s: { fill: { fgColor: { rgb: "E9E9E9" } } } }, |
| 49 | + { v: "line\nbreak", t: "s", s: { alignment: { wrapText: true } } }, |
| 50 | +]; |
| 51 | + |
| 52 | +// STEP 3: Create worksheet with rows; Add worksheet to workbook |
| 53 | +const ws = XLSX.utils.aoa_to_sheet([row]); |
| 54 | +XLSX.utils.book_append_sheet(wb, ws, "readme demo"); |
| 55 | + |
| 56 | +// STEP 4: Write Excel file to browser |
| 57 | +XLSX.writeFile(wb, "xlsx-js-style-demo.xlsx"); |
44 | 58 | ``` |
45 | 59 |
|
46 | 60 | ### Cell Style Properties |
47 | 61 |
|
48 | | -Cell styles are specified by a style object that roughly parallels the OpenXML structure. The style object has five |
49 | | -top-level attributes: `fill`, `font`, `numFmt`, `alignment`, and `border`. |
50 | | - |
51 | | -| Style Attribute | Sub Attributes | Values | |
52 | | -| :-------------- | :------------- | :-------------------------------------------------------------------------------------------- | |
53 | | -| fill | patternType | `"solid"` or `"none"` | |
54 | | -| | fgColor | `COLOR_SPEC` | |
55 | | -| | bgColor | `COLOR_SPEC` | |
56 | | -| font | name | `"Calibri"` // default | |
57 | | -| | sz | `"11"` // font size in points | |
58 | | -| | color | `COLOR_SPEC` | |
59 | | -| | bold | `true` or `false` | |
60 | | -| | underline | `true` or `false` | |
61 | | -| | italic | `true` or `false` | |
62 | | -| | strike | `true` or `false` | |
63 | | -| | outline | `true` or `false` | |
64 | | -| | shadow | `true` or `false` | |
65 | | -| | vertAlign | `true` or `false` | |
66 | | -| numFmt | | `"0"` // integer index to built in formats, see StyleBuilder.SSF property | |
67 | | -| | | `"0.00%"` // string matching a built-in format, see StyleBuilder.SSF | |
68 | | -| | | `"0.0%"` // string specifying a custom format | |
69 | | -| | | `"0.00%;\\(0.00%\\);\\-;@"` // string specifying a custom format, escaping special characters | |
70 | | -| | | `"m/dd/yy"` // string a date format using Excel's format notation | |
71 | | -| alignment | vertical | `"bottom"` or `"center"` or `"top"` | |
72 | | -| | horizontal | `"left"` or `"center"` or `"right"` | |
73 | | -| | wrapText | `true ` or ` false` | |
74 | | -| | readingOrder | `2` // for right-to-left | |
75 | | -| | textRotation | Number from `0` to `180` or `255` (default is `0`) | |
76 | | -| | | `90` is rotated up 90 degrees | |
77 | | -| | | `45` is rotated up 45 degrees | |
78 | | -| | | `135` is rotated down 45 degrees | |
79 | | -| | | `180` is rotated down 180 degrees | |
80 | | -| | | `255` is special, aligned vertically | |
81 | | -| border | top | `{ style: BORDER_STYLE, color: COLOR_SPEC }` | |
82 | | -| | bottom | `{ style: BORDER_STYLE, color: COLOR_SPEC }` | |
83 | | -| | left | `{ style: BORDER_STYLE, color: COLOR_SPEC }` | |
84 | | -| | right | `{ style: BORDER_STYLE, color: COLOR_SPEC }` | |
85 | | -| | diagonal | `{ style: BORDER_STYLE, color: COLOR_SPEC }` | |
86 | | -| | diagonalUp | `true` or `false` | |
87 | | -| | diagonalDown | `true` or `false` | |
88 | | - |
89 | | -**COLOR_SPEC**: Colors for `fill`, `font`, and `border` are specified as objects, either: |
90 | | - |
91 | | -- `{ auto: 1}` specifying automatic values |
92 | | -- `{ rgb: "FFFFAA00" }` specifying a hex ARGB value |
93 | | -- `{ theme: "1", tint: "-0.25"}` specifying an integer index to a theme color and a tint value (default 0) |
94 | | -- `{ indexed: 64}` default value for `fill.bgColor` |
95 | | - |
96 | | -**BORDER_STYLE**: Border style is a string value which may take on one of the following values: |
| 62 | +- Cell styles are specified by a style object that roughly parallels the OpenXML structure. |
| 63 | +- Style properties currently supported are: `alignment`, `border`, `fill`, `font`, `numFmt`. |
| 64 | + |
| 65 | +| Style Prop | Sub Prop | Default | Description/Values | |
| 66 | +| :---------- | :------------- | :---------- | ------------------------------------------------------------------------------------------------- | |
| 67 | +| `alignment` | `vertical` | `bottom` | `"top"` or `"center"` or `"bottom"` | |
| 68 | +| | `horizontal` | `left` | `"left"` or `"center"` or `"right"` | |
| 69 | +| | `wrapText` | `false` | `true` or `false` | |
| 70 | +| | `textRotation` | `0` | `0` to `180`, or `255` // `180` is rotated down 180 degrees, `255` is special, aligned vertically | |
| 71 | +| `border` | `top` | | `{ style: BORDER_STYLE, color: COLOR_STYLE }` | |
| 72 | +| | `bottom` | | `{ style: BORDER_STYLE, color: COLOR_STYLE }` | |
| 73 | +| | `left` | | `{ style: BORDER_STYLE, color: COLOR_STYLE }` | |
| 74 | +| | `right` | | `{ style: BORDER_STYLE, color: COLOR_STYLE }` | |
| 75 | +| | `diagonal` | | `{ style: BORDER_STYLE, color: COLOR_STYLE, diagonalUp: true/false, diagonalDown: true/false }` | |
| 76 | +| `fill` | `patternType` | `"none"` | `"solid"` or `"none"` | |
| 77 | +| | `fgColor` | | foreground color: see `COLOR_STYLE` | |
| 78 | +| | `bgColor` | | background color: see `COLOR_STYLE` | |
| 79 | +| `font` | `bold` | `false` | font bold `true` or `false` | |
| 80 | +| | `color` | | font color `COLOR_STYLE` | |
| 81 | +| | `italic` | `false` | font italic `true` or `false` | |
| 82 | +| | `name` | `"Calibri"` | font name | |
| 83 | +| | `strike` | `false` | font strikethrough `true` or `false` | |
| 84 | +| | `sz` | `"11"` | font size (points) | |
| 85 | +| | `underline` | `false` | font underline `true` or `false` | |
| 86 | +| | `vertAlign` | | `"superscript"` or `"subscript"` | |
| 87 | +| `numFmt` | | `0` | Ex: `"0"` // integer index to built in formats, see StyleBuilder.SSF property | |
| 88 | +| | | | Ex: `"0.00%"` // string matching a built-in format, see StyleBuilder.SSF | |
| 89 | +| | | | Ex: `"0.0%"` // string specifying a custom format | |
| 90 | +| | | | Ex: `"0.00%;\\(0.00%\\);\\-;@"` // string specifying a custom format, escaping special characters | |
| 91 | +| | | | Ex: `"m/dd/yy"` // string a date format using Excel's format notation | |
| 92 | + |
| 93 | +### `COLOR_STYLE` {object} Properties |
| 94 | + |
| 95 | +Colors for `border`, `fill`, `font` are specified as an name/value object - use one of the following: |
| 96 | + |
| 97 | +| Color Prop | Description | Example | |
| 98 | +| :--------- | ----------------- | --------------------------------------------------------------- | |
| 99 | +| `rgb` | hex RGB value | `{rgb: "FFCC00"}` | |
| 100 | +| `theme` | theme color index | `{theme: 4}` // (0-n) // Theme color index 4 ("Blue, Accent 1") | |
| 101 | +| `tint` | tint by percent | `{theme: 1, tint: 0.4}` // ("Blue, Accent 1, Lighter 40%") | |
| 102 | + |
| 103 | +### `BORDER_STYLE` {string} Properties |
| 104 | + |
| 105 | +Border style property is one of the following values: |
97 | 106 |
|
98 | | -- `thin` |
99 | | -- `medium` |
100 | | -- `thick` |
| 107 | +- `dashDotDot` |
| 108 | +- `dashDot` |
| 109 | +- `dashed` |
101 | 110 | - `dotted` |
102 | 111 | - `hair` |
103 | | -- `dashed` |
104 | | -- `mediumDashed` |
105 | | -- `dashDot` |
106 | | -- `mediumDashDot` |
107 | | -- `dashDotDot` |
108 | 112 | - `mediumDashDotDot` |
| 113 | +- `mediumDashDot` |
| 114 | +- `mediumDashed` |
| 115 | +- `medium` |
109 | 116 | - `slantDashDot` |
| 117 | +- `thick` |
| 118 | +- `thin` |
| 119 | + |
| 120 | +**Border Notes** |
110 | 121 |
|
111 | | -Borders for merged areas are specified for each cell within the merged area. So to apply a box border to a merged area of 3x3 cells, border styles would need to be specified for eight different cells: |
| 122 | +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: |
112 | 123 |
|
113 | | -- left borders for the three cells on the left, |
114 | | -- right borders for the cells on the right |
115 | | -- top borders for the cells on the top |
116 | | -- bottom borders for the cells on the left |
| 124 | +- left borders (for the three cells on the left) |
| 125 | +- right borders (for the cells on the right) |
| 126 | +- top borders (for the cells on the top) |
| 127 | +- bottom borders (for the cells on the left) |
117 | 128 |
|
118 | 129 | ## 🙏 Thanks |
119 | 130 |
|
| 131 | +This project is a fork of [SheetJS/sheetjs](https://github.com/sheetjs/sheetjs) combined with code from |
| 132 | +[sheetjs-style](https://www.npmjs.com/package/sheetjs-style) (by [ShanaMaid](https://github.com/ShanaMaid/)) |
| 133 | +and [sheetjs-style-v2](https://www.npmjs.com/package/sheetjs-style-v2) (by [Raul Gonzalez](https://www.npmjs.com/~armandourbina)). |
| 134 | + |
| 135 | +All projects are under the Apache 2.0 License |
| 136 | + |
120 | 137 | - [sheetjs](https://github.com/SheetJS/sheetjs) |
121 | 138 | - [js-xlsx](https://github.com/protobi/js-xlsx) |
122 | 139 | - [sheetjs-style](https://www.npmjs.com/package/sheetjs-style) |
123 | 140 | - [sheetjs-style-v2](https://www.npmjs.com/package/sheetjs-style-v2) |
124 | 141 |
|
125 | 142 | ## 🔖 License |
126 | 143 |
|
127 | | -Please consult the attached LICENSE file for details. All rights not explicitly |
| 144 | +Please consult the attached [LICENSE](https://github.com/gitbrent/xlsx-js-style/blob/master/LICENSE) file for details. All rights not explicitly |
128 | 145 | granted by the Apache 2.0 License are reserved by the Original Author. |
0 commit comments