style-xlsx-m 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -41
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ Install browser:
|
|
|
41
41
|
// STEP 1
|
|
42
42
|
// './excample.xlsx' - is a path to your excel file.
|
|
43
43
|
// Second property is a option { cellStyle: true } for get cells style (but now can't get in xls format).
|
|
44
|
-
const workbook = XLSX.readFile('./example.xlsx',{ cellStyles: true
|
|
44
|
+
const workbook = XLSX.readFile('./example.xlsx',{ cellStyles: true });
|
|
45
45
|
|
|
46
46
|
// STEP 2 Create data rows worksheet
|
|
47
47
|
let worksheet = [
|
|
@@ -56,7 +56,7 @@ let worksheet = [
|
|
|
56
56
|
// STEP 3 Get workbook data with style and set workbook.Sheets.sheetname to worksheet
|
|
57
57
|
XLSX.utils.book_append_sheet(workbook, worksheet, false, false, sheetname);
|
|
58
58
|
|
|
59
|
-
// STEP 4 Save your file with style
|
|
59
|
+
// STEP 4 Save your file with style
|
|
60
60
|
XLSX.writeFile(wb, "style-xlsx-m-example.xlsm");
|
|
61
61
|
```
|
|
62
62
|
This example shows how you can change the contents of a file without removing its old style.
|
|
@@ -65,32 +65,11 @@ XLSX.writeFile(wb, "style-xlsx-m-example.xlsm");
|
|
|
65
65
|
## 🗒 Style API
|
|
66
66
|
-- Method to export file in excel with style get from [xlsx-js-style](https://www.npmjs.com/package/xlsx-js-style) (only function writeFile)
|
|
67
67
|
|
|
68
|
-
### Cell Style Example
|
|
69
|
-
|
|
70
|
-
```js
|
|
71
|
-
// STEP 1: Create a new workbook
|
|
72
|
-
const wb = XLSX.utils.book_new();
|
|
73
|
-
|
|
74
|
-
// STEP 2: Create data rows and styles
|
|
75
|
-
let row = [
|
|
76
|
-
{ v: "line\nbreak", t: "s", s: { alignment: { wrapText: true } } },
|
|
77
|
-
{ v: "Courier: 24", t: "s", s: { font: { name: "Courier", sz: 24 } } },
|
|
78
|
-
{ v: "fill: color", t: "s", s: { fill: { fgColor: { rgb: "E9E9E9" } } } },
|
|
79
|
-
{ v: "bold & color", t: "s", s: { font: { bold: true, color: { rgb: "FF0000" } } } },
|
|
80
|
-
];
|
|
81
|
-
|
|
82
|
-
// STEP 3: Create worksheet with rows; Add worksheet to workbook
|
|
83
|
-
const ws = XLSX.utils.aoa_to_sheet([row]);
|
|
84
|
-
XLSX.utils.book_append_sheet(wb, ws, "readme demo");
|
|
85
|
-
|
|
86
|
-
// STEP 4: Write Excel file to browser
|
|
87
|
-
XLSX.writeFile(wb, "xlsx-js-style-demo.xlsx");
|
|
88
|
-
```
|
|
89
68
|
|
|
90
69
|
### Cell Style JSON structure
|
|
91
70
|
|
|
92
71
|
- Cell styles are specified by a style object that roughly parallels the OpenXML structure.
|
|
93
|
-
- Style properties currently supported are: `alignment`, `border`, `fill`, `font
|
|
72
|
+
- Style properties currently supported are: `alignment`, `border`, `fill`, `font`.
|
|
94
73
|
|
|
95
74
|
|
|
96
75
|
```js
|
|
@@ -156,6 +135,28 @@ XLSX.writeFile(wb, "xlsx-js-style-demo.xlsx");
|
|
|
156
135
|
|
|
157
136
|
```
|
|
158
137
|
|
|
138
|
+
|
|
139
|
+
### Cell Style Example
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
// STEP 1: Create a new workbook
|
|
143
|
+
const wb = XLSX.utils.book_new();
|
|
144
|
+
|
|
145
|
+
// STEP 2: Create data rows and styles
|
|
146
|
+
let row = [
|
|
147
|
+
{ v: "line\nbreak", t: "s", s: { alignment: { wrapText: true } } },
|
|
148
|
+
{ v: "Courier: 24", t: "s", s: { font: { name: "Courier", sz: 24 } } },
|
|
149
|
+
{ v: "fill: color", t: "s", s: { fill: { fgColor: { rgb: "E9E9E9" } } } },
|
|
150
|
+
{ v: "bold & color", t: "s", s: { font: { bold: true, color: { rgb: "FF0000" } } } },
|
|
151
|
+
];
|
|
152
|
+
|
|
153
|
+
// STEP 3: Create worksheet with rows; Add worksheet to workbook
|
|
154
|
+
const ws = XLSX.utils.aoa_to_sheet([row]);
|
|
155
|
+
XLSX.utils.book_append_sheet(wb, ws, "readme demo");
|
|
156
|
+
|
|
157
|
+
// STEP 4: Write Excel file to browser
|
|
158
|
+
XLSX.writeFile(wb, "xlsx-js-style-demo.xlsx");
|
|
159
|
+
```
|
|
159
160
|
<!-- | Style Prop | Sub Prop | Default | Description/Values |
|
|
160
161
|
| :---------- | :------------- | :---------- | ------------------------------------------------------------------------------------------------- |
|
|
161
162
|
| `alignment` | `vertical` | `bottom` | `"top"` or `"center"` or `"bottom"` |
|
|
@@ -184,6 +185,7 @@ XLSX.writeFile(wb, "xlsx-js-style-demo.xlsx");
|
|
|
184
185
|
| | | | Ex: `"0.00%;\\(0.00%\\);\\-;@"` // string specifying a custom format, escaping special characters |
|
|
185
186
|
| | | | Ex: `"m/dd/yy"` // string a date format using Excel's format notation | -->
|
|
186
187
|
|
|
188
|
+
|
|
187
189
|
### `COLOR_STYLE` {object} Properties
|
|
188
190
|
|
|
189
191
|
Colors for `border`, `fill`, `font` are specified as an name/value object - use one of the following:
|
|
@@ -191,25 +193,23 @@ Colors for `border`, `fill`, `font` are specified as an name/value object - use
|
|
|
191
193
|
|
|
192
194
|
```js
|
|
193
195
|
// JSON structure
|
|
194
|
-
const
|
|
196
|
+
const COLOR_STYLE = { // hex RGB value
|
|
195
197
|
rgb: 'FFCC00'
|
|
196
198
|
}
|
|
197
|
-
|
|
198
|
-
const theme = {
|
|
199
|
+
const COLOR_STYLE = { // theme color index
|
|
199
200
|
theme: 4 // (0-n) // Theme color index 4 ("Blue, Accent 1")
|
|
200
201
|
}
|
|
201
|
-
|
|
202
|
-
const tint = {
|
|
202
|
+
const COLOR_STYLE = { // tint by percent
|
|
203
203
|
theme: 1,
|
|
204
|
-
tint: 0.4
|
|
205
|
-
}
|
|
204
|
+
tint: 0.4 // ("Blue, Accent 1, Lighter 40%")
|
|
205
|
+
}
|
|
206
206
|
```
|
|
207
|
-
|
|
208
|
-
| Color Prop | Description | Example |
|
|
207
|
+
<!-- | Color Prop | Description | Example |
|
|
209
208
|
| :--------- | ----------------- | --------------------------------------------------------------- |
|
|
210
209
|
| `rgb` | hex RGB value | `{rgb: "FFCC00"}` |
|
|
211
210
|
| `theme` | theme color index | `{theme: 4}` // (0-n) // Theme color index 4 ("Blue, Accent 1") |
|
|
212
|
-
| `tint` | tint by percent | `{theme: 1, tint: 0.4}` // ("Blue, Accent 1, Lighter 40%") |
|
|
211
|
+
| `tint` | tint by percent | `{theme: 1, tint: 0.4}` // ("Blue, Accent 1, Lighter 40%") | -->
|
|
212
|
+
|
|
213
213
|
|
|
214
214
|
### `BORDER_STYLE` {string} Properties
|
|
215
215
|
|
|
@@ -217,14 +217,11 @@ Border style property is one of the following values:
|
|
|
217
217
|
|
|
218
218
|
`dashDotDot`, `dashDot`, `dashed`, `dotted`, `hair`, `mediumDashDotDot`, `mediumDashDot`, `mediumDashed`, `medium`, `slantDashDot`, `thick`, `thin`
|
|
219
219
|
|
|
220
|
-
**Border Notes**
|
|
221
|
-
|
|
222
|
-
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:
|
|
223
220
|
|
|
224
|
-
|
|
225
|
-
-
|
|
226
|
-
-
|
|
227
|
-
-
|
|
221
|
+
## 🗒 TODO
|
|
222
|
+
- optimize the project
|
|
223
|
+
- add new features for tasks and libraries (for example: spreadsheet)
|
|
224
|
+
- (If you have any ideas and/or suggestions write in my [email](hp.sh.shahrom@gmail.com) or [github](https://github.com/MOR8T))
|
|
228
225
|
|
|
229
226
|
## 🙏 Thanks
|
|
230
227
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "style-xlsx-m",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"author": "mor8t (Shukurov Shahrom)",
|
|
5
5
|
"description": "style-xlsx-m is a custom xlsx and xlsx-js-style version library",
|
|
6
6
|
"keywords": [
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"bugs": {
|
|
96
96
|
"url": "https://github.com/MOR8T/STYLE-XSLX-M"
|
|
97
97
|
},
|
|
98
|
-
"license": "Apache-
|
|
98
|
+
"license": "Apache-2.0",
|
|
99
99
|
"engines": {
|
|
100
100
|
"node": ">=0.8"
|
|
101
101
|
}
|